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
merged 3 commits into from Jan 19, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,11 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA
* [JRuby] `{XML,HTML}::Document.parse` now invokes `#initialize` exactly once. Previously `#initialize` was not called, which was a problem for subclassing such as done by `Loofah`.


### Improved

* [JRuby] Update the algorithm used to calculate `Node#line` to be wrong less-often. The underlying parser, Xerces, does not track line numbers, and so we've always used a hacky solution for this method. [[#1223](https://github.com/sparklemotion/nokogiri/issues/1223)]


## v1.11.1 / 2021-01-06

### Fixed
Expand Down
20 changes: 14 additions & 6 deletions ext/java/nokogiri/XmlNode.java
Expand Up @@ -1406,14 +1406,22 @@ private boolean count(Node node, int[] counter) {
if (node == this.node) {
return true;
}

NodeList list = node.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
Node n = list.item(i);
if (n instanceof Text
&& ((Text)n).getData().contains("\n")) {
counter[0] += 1;
for (int jchild=0; jchild<list.getLength(); jchild++) {
Node child = list.item(jchild);

if (child instanceof Text) {
String text = ((Text)child).getData();
int textLength = text.length();
for (int jchar = 0; jchar < textLength; jchar++) {
if (text.charAt(jchar) == '\n') {
counter[0] += 1;
}
}
}
if (count(n, counter)) return true;

if (count(child, counter)) return true;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion nokogiri.gemspec
Expand Up @@ -300,7 +300,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency("bundler", "~> 2.2")
spec.add_development_dependency("concourse", "~> 0.41")
spec.add_development_dependency("hoe-markdown", "~> 1.1")
spec.add_development_dependency("hoe-markdown", "~> 1.4")
spec.add_development_dependency("minitest", "~> 5.8")
spec.add_development_dependency("minitest-reporters", "~> 1.4")
spec.add_development_dependency("rake", "~> 13.0")
Expand Down
2 changes: 1 addition & 1 deletion rakelib/markdown.rake
@@ -1,2 +1,2 @@
require "hoe/markdown"
Hoe::Markdown::Standalone.new("nokogiri").define_markdown_tasks
Hoe::Markdown::Standalone.new("nokogiri").define_markdown_tasks("CHANGELOG.md")