Bug #4067: [PATCH] Fix SystemStackError when trying to format a large blo=
ck of text in REXML
http://redmine.ruby-lang.org/issues/show/4067

Author: Jeremy Evans
Status: Open, Priority: Normal
Category: lib
ruby -v: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-openbsd4.8]

REXML::Formatters::Pretty#wrap used a recursive method call to format tex=
t.  This patch switches it to use an iterative approach.  It includes a t=
est case exposing the error.

This issue isn't theoretical, it happens when using rcov with Sequel's te=
st suite.

Tested on 1.9.2p0, but patch is against trunk.


----------------------------------------
http://redmine.ruby-lang.org
RnJvbSBiNTIyZjgxNTAwMWVkMTI0YWY1M2Y1ZjNiYmFlZDc4MTU2YTJmZTRj
IE1vbiBTZXAgMTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBKZXJlbXkgRXZhbnMg
PGNvZGVAamVyZW15ZXZhbnMubmV0PgpEYXRlOiBXZWQsIDE3IE5vdiAyMDEw
IDE0OjE3OjU0IC0wODAwClN1YmplY3Q6IFtQQVRDSF0gRml4IFN5c3RlbVN0
YWNrRXJyb3Igd2hlbiB0cnlpbmcgdG8gZm9ybWF0IGEgbGFyZ2UgYmxvY2sg
b2YgdGV4dCBpbiBSRVhNTAoKUkVYTUw6OkZvcm1hdHRlcnM6OlByZXR0eSN3
cmFwIHVzZWQgYSByZWN1cnNpdmUgbWV0aG9kIGNhbGwgdG8gZm9ybWF0CnRl
eHQuICBUaGlzIHN3aXRjaGVzIGl0IHRvIHVzZSBhbiBpdGVyYXRpdmUgYXBw
cm9hY2guCi0tLQogbGliL3JleG1sL2Zvcm1hdHRlcnMvcHJldHR5LnJiIHwg
ICAxMyArKysrKysrKy0tLS0tCiB0ZXN0L3JleG1sL3Rlc3RfY29yZS5yYiAg
ICAgICAgfCAgICA3ICsrKysrKysKIDIgZmlsZXMgY2hhbmdlZCwgMTUgaW5z
ZXJ0aW9ucygrKSwgNSBkZWxldGlvbnMoLSkKCmRpZmYgLS1naXQgYS9saWIv
cmV4bWwvZm9ybWF0dGVycy9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