Repository navigation
Conversation
…nd() for negative halves
substring('12345', 0) returned '1234' and substring('12345', -1 div 0)
returned '' because the two-argument form subtracted the start offset
from the string length. round(-2.5) returned -3 and round(-0.5)
returned -1 because negative numbers were rounded half away from zero.
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
substring()drops characters when the start is before the first character, andround()rounds negative halves the wrong way.substring('12345', 0)12341234512345substring('12345', -1)1231234512345substring('12345', -1 div 0)1234512345substring('12345', -0.5, 1.5)11round(-2.5)-3-2-2round(-0.5)-1-0-01 div round(-0.4)Infinity-Infinity-InfinityCause:
ruby_length += ruby_start), so every position before 1 cut one more character off the end. A-Infinitystart returned''right away.round()roundedabs(n)with Ruby's half-away-from-zero rule and put the sign back, so-2.5became-3.https://www.w3.org/TR/xpath-10/#function-substring
https://www.w3.org/TR/xpath-10/#function-round
substring()now follows that rule directly: keep positionspwithround(start) <= p < round(start) + round(length)(no upper bound when there is no length). NaN bounds still give'', so the existing spec examples (substring("12345", 0 div 0, 3),substring("12345", -1 div 0, 1 div 0), ...) keep passing.The two new tests fail on master and pass here.
bundle exec rake testpasses (843 tests). I also ran ~2,300 XPath expressions (substring with many start/length values, round/floor/ceiling, comparisons, axes) against libxml2 through lxml: all substring and round differences are gone, and no other result changed.