Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(jruby) Fix Node#line #2177

merged 3 commits into from Jan 19, 2021

(jruby) Fix Node#line #2177

merged 3 commits into from Jan 19, 2021


Copy link

What problem is this PR intended to solve?

#1223 to make Node#line on JRuby smarter.

For background, the Java DOM interfaces don't provide any way for a Node to know or find the line number in the original document at which it appeared.

I'm unhappy with this approach, but was unable to figure out how to make the original approach at #1223 work. If you're familiar with the Java DOM interfaces and want to help, please do.

Have you included adequate test coverage?


Does this change affect the behavior of either the C or the Java implementations?

The Java implementation's behavior should be closer to the C implementation's behavior now.

Note that Java's w3c.dom.Node interface does not have any way to
get (or set) the line number for that node. The original JRuby
implementation counted newlines, but did it poorly -- see #1223.

This commit improves the newline-counting approach. But the solution
itself -- counting newlines! -- is still questionable IMHO and
absolutely inefficient.

I had played around with an approach that I wrote about at #1223,
where the SAX Parser knows what line it's on when `startElement` is
invoked (via the XMLLocator). But I couldn't figure out how to
preserve that information in the final Document or Node.

If you, like me, think this approach is terrible; and if you *also*
understand how to set this metadata on the Node or the Document, then
please help us out.
@flavorjones flavorjones merged commit be33917 into main Jan 19, 2021
@flavorjones flavorjones deleted the flavorjones-1223-jruby-line-numbers branch January 19, 2021 13:03
@flavorjones flavorjones added this to the v1.11.x patch releases milestone Mar 8, 2021
This was referenced Mar 11, 2021
This was referenced Mar 18, 2021
flavorjones added a commit that referenced this pull request Aug 14, 2021
feat(cruby): support line numbers larger than a short


**What problem is this PR intended to solve?**

As noted in #1493, #1617, #1505, #1003, and #533, libxml2 has not historically supported line numbers greater than a `short int`. Starting in libxml v2.9.0, setting the parse option `BIG_LINES` would allow tracking line numbers in longer documents.

Specifically this PR makes the following changes:

- set `BIG_LINES` parse option by default which will allow `Node#line` to return large integers
- allow `Node#line=` to set large line numbers on text nodes

Fixes #1764 

**Have you included adequate test coverage?**


**Does this change affect the behavior of either the C or the Java implementations?**

JRuby's Xerces-based implementation did not suffer from this particular shortcoming, although its line number functionality is questionable in other ways (see #2177 / b32c875).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

1 participant