Porting REXML to Ruby 1.9
Unicode changes:
- baseparser.rb and source.rb were changed to force encoding to utf-8.
- XPath function
translateconverted to support characters - Comparing indexed strings against numbers was changed to compare slices against strings.
- Encoding specific tests were changed as necessary to specify the encoding expected.
Other language changes:
{"a","b"}no longer supported, converted to{"a"=>"b"}Array.to_snow contains square brackets, quotes, and commas.Array.joinused instead when join semantics is required.- Colon is no longer accepted as an alternative to
theninwhenstatements. - Renamed variables when necessary to prevent warning message when a block variable shadowed a local variable. The idiom
var = array.find {|var| ...}now requires the block variable to be named differently than the local variable. REXML also has a few places where block variables were set tonilimmediately outside of the block “for performance reasons”. In a few cases,for node in nodesetwas replaced withnodeset.each do |node| Hash.indexchanged toHash.keyEnumeration.zipno longer insertsnils to pad out arrays.- An instance variable which previously wasn’t initialized now explicitly initialized to false
- Added a
sleepin a threaded sax/socket test to prevent a race condition.
REXML changes:
- Substitution of entities was done in a single pass, this meant that entity values whose value referenced other entities would only get fully expanded if the order of the hash matched the order of evaluation.
get_attribute_ns('','a')previously matched both an attribute nameda, andxmlns:a. Which one returned depended on the order of a hash. Changed the method to only selecta.- One regular expression which had explicitly specified
/ufor unicode changed to not be unicode: this was the regular expression matching the xml prolog declaration itself which must be matched against bytes. - Added a unit test for 110 and tests and fixes for 123, 127.
Outputs of running bin/suite.rb:
["3.1.7.2", "1.9.0", "2007-12-31"] REXML version = 3.1.7.2 Loaded suite REXML Started ............................................................................................................................................................................................................................................................................................................................................................ Finished in 12.893064488 seconds. 348 tests, 1252 assertions, 0 failures, 0 errors
["3.1.7.2", "1.8.6", "2007-06-07"] REXML version = 3.1.7.2 Loaded suite REXML Started ............................................................................................................................................................................................................................................................................................................................................................ Finished in 34.733291 seconds. 348 tests, 1252 assertions, 0 failures, 0 errors
Renamed variables when necessary to prevent warning message when a block variable shadowed a local variable. The idiom var = array.find {|var| ...} now requires the block variable to be named differently than the local variable.
A good trick is to prefix the inner variable with the “_” character. It goes fast and is informative. So in that example, it would give: var = array.find {|_var| ...}
Posted by zimbatm atNow That’s a Patch
I refer to Sam Ruby’s massive patch to make REXML work properly with the latest Ruby. I’ve long disliked REXML (see here and here ), but it’s here and it works. Only the way it works changed in 1.9, and there were some horrible regressions, and it...Excerpt from ongoing at
Getting Code Ready for Ruby 1.9
In Getting Code Ready for Ruby 1.9, James Edward Gray II is attempting to put together a comprehensive blog post on the various things you need to do to migrate your Ruby 1.8 code over to working on Ruby 1.9. So far, James only looks at a handful of...Excerpt from Ruby Inside at
Tor Norbye: Ruby Screenshot of the Week #26: Ruby 1.9 Changes - hashes and case statements
Ruby 1.9 has been released . It’s a “development” version meaning that you wouldn’t want to use it in production, but now is a good time to learn the new ways of doing things such that migrating to Ruby 2.0 will be easier. Via Ruby Inside...Excerpt from Tor Norbye's Weblog at
The Ruby News
I keep putting off this Ruby News Survey piece because there keeps being more news, but hey, you have to pull the trigger sometime....Excerpt from ongoing at
REXML a Drag...Again
We’ve been here before. So here’s the scenario: You’re feeding medium-to-large chunks of XML out of one Rails app, to be consumed by another via ActiveResource . Maybe those chunks have embedded HTML, or maybe they’re an...Excerpt from Nick Sieger: REXML a Drag...Again at
Sam Ruby: Porting REXML to Ruby 1.9
[link] [more]...Excerpt from programming: what's new online at