Ticket #135 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Unable to print out XML if text has more than 80 chars without whitespace

Reported by: curious_george Owned by: rubys
Priority: normal Milestone:
Component: DOM Version: 3.1.7
Severity: normal Keywords:
Cc: Ruby version: Other
Operating system: Windows

Description

Description:
When attempting to print out an XML document, I receive the following error: TypeError?: no implicit conversion from nil to integer

See attached file for a small test case.

This appears to be caused by a Text element that is longer than 80 characters and has no whitespace. In the wrap method of pretty.rb, the following two lines are important:

        place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
        return string[0,place] + "\n" + wrap(string[place+1..-1], width)

If there is no space, 'place' is nil. The following line then attempts to calculate string[0,nil] --- this gives the error.

Notes:

There are two ways to work around it.

The easiest way is to insert a space into the test value, if possible.

Alternatively, override the wrap method to prevent any wrapping with the following code:

REXML::Formatters::Pretty.class_eval(
      %Q^def wrap(string, width)
        return string
      end^
)

Environment:

ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
"3.1.7.1"
"i386-mswin32"

Attachments

rubytest.rb (0.6 kB) - added by curious_george 3 years ago.

Change History

Changed 3 years ago by curious_george

Changed 3 years ago by rubys

  • owner changed from ser to rubys

Changed 3 years ago by rubys

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.