[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: gsub choking on fixnum

Yukihiro Matsumoto

5/20/2009 11:54:00 PM

Hi,

In message "Re: gsub choking on fixnum"
on Thu, 21 May 2009 08:37:58 +0900, Cali Wildman <caliwildman2004-info@yahoo.com> writes:

|Here's the code in question, I'm using REXML Document
|
| doc = Document.new(entry.embed_code)
| doc.root.each_element('//embed | //object'){ |elem|
| elem.attributes['height'] = 140 #this is line 57, see error
|below
| elem.attributes['width'] = 170
| }

The following patch should work.

matz.
diff --git a/ChangeLog b/ChangeLog
index b5bd805..1edb627 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu May 21 08:50:58 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/rexml/text.rb (REXML::Text.normalize): call to_s for input.
+ [ruby-talk:337069]
+
Mon May 18 21:40:11 2009 Tanaka Akira <akr@fsij.org>

* lib/pathname.rb (Pathname#sub): suppress a warning.
diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb
index 2bc0042..a4a30b6 100644
--- a/lib/rexml/text.rb
+++ b/lib/rexml/text.rb
@@ -286,7 +286,7 @@ module REXML
EREFERENCE = /&(?!#{Entity::NAME};)/
# Escapes all possible entities
def Text::normalize( input, doctype=nil, entity_filter=nil )
- copy = input
+ copy = input.to_s
# Doing it like this rather than in a loop improves the speed
#copy = copy.gsub( EREFERENCE, '&amp;' )
copy = copy.gsub( "&", "&amp;" )

2 Answers

Cali Wildman

5/21/2009 4:30:00 AM

0

Yukihiro Matsumoto wrote:
> matz.
> diff --git a/ChangeLog b/ChangeLog
> index b5bd805..1edb627 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +Thu May 21 08:50:58 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
> +
> + * lib/rexml/text.rb (REXML::Text.normalize): call to_s for input.
> + [ruby-talk:337069]
> +
> Mon May 18 21:40:11 2009 Tanaka Akira <akr@fsij.org>
>
> * lib/pathname.rb (Pathname#sub): suppress a warning.
> diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb
> index 2bc0042..a4a30b6 100644
> --- a/lib/rexml/text.rb
> +++ b/lib/rexml/text.rb
> @@ -286,7 +286,7 @@ module REXML
> EREFERENCE = /&(?!#{Entity::NAME};)/
> # Escapes all possible entities
> def Text::normalize( input, doctype=nil, entity_filter=nil )
> - copy = input
> + copy = input.to_s
> # Doing it like this rather than in a loop improves the speed
> #copy = copy.gsub( EREFERENCE, '&amp;' )
> copy = copy.gsub( "&", "&amp;" )

This is a change in the REXML code, if I have to make a change, I'm more
comfortable with changing my own code. Is this change a REXML bug fix or
simply a fix for my problem? I'm still trying to figure out if 1.8.6
introduced a bug of some kind whether it be in gsub or REXML.
--
Posted via http://www.ruby-....

Brian Candler

5/21/2009 10:00:00 AM

0

Yukihiro Matsumoto wrote:
> The following patch should work.
...
> index 2bc0042..a4a30b6 100644
> --- a/lib/rexml/text.rb
> +++ b/lib/rexml/text.rb
> @@ -286,7 +286,7 @@ module REXML
> EREFERENCE = /&(?!#{Entity::NAME};)/
> # Escapes all possible entities
> def Text::normalize( input, doctype=nil, entity_filter=nil )
> - copy = input
> + copy = input.to_s
> # Doing it like this rather than in a loop improves the speed
> #copy = copy.gsub( EREFERENCE, '&amp;' )
> copy = copy.gsub( "&", "&amp;" )

...which was also posted here
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/c2e2f3b9a6ffac50/95e9a6...
--
Posted via http://www.ruby-....