Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/rexml/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,15 @@ def string( object=@context[:node] )
if object == integer
"%d" % integer
else
object.to_s
str = object.to_s
if str.include?("e-")
sign = str.start_with?("-") ? "-" : ""
mantissa, exp = str.delete_prefix("-").split("e-", 2)
digits = mantissa.delete(".").sub(/0+\z/, "")
"#{sign}0.#{'0' * (exp.to_i - 1)}#{digits}"
else
str
end
end
end
else
Expand Down
9 changes: 9 additions & 0 deletions test/functions/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ def test_string_infinity
])
end

def test_string_small_float
doc = REXML::Document.new("<a/>")
assert_equal("0.00001", REXML::XPath.first(doc, "string(0.00001)"))
assert_equal("-0.00001", REXML::XPath.first(doc, "string(-0.00001)"))
assert_equal("0.0000123", REXML::XPath.first(doc, "string(0.0000123)"))
assert_equal("0.0000000001", REXML::XPath.first(doc, "string(1 div 10000000000)"))
assert_equal(0.00001, REXML::XPath.first(doc, "number(string(0.00001))"))
end

# Submitted by Kou
def test_lang
d = Document.new(<<-XML)
Expand Down
Loading