Skip to content

Commit

Permalink
Revert 3f2e575 and f7a3817
Browse files Browse the repository at this point in the history
The fix for #444 turns out to cause issues with frozen strings
(see #1077). Furthermore, MRI as of this commit behaves similar to
JRuby, i.e. it adds the extra newline at the end of the fragment.
  • Loading branch information
jvshahid committed Feb 18, 2016
1 parent c08e913 commit 233571a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
14 changes: 0 additions & 14 deletions ext/java/nokogiri/XmlDocumentFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;

/**
Expand Down Expand Up @@ -90,7 +89,6 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObj

// make wellformed fragment, ignore invalid namespace, or add appropriate namespace to parse
if (args.length > 1 && args[1] instanceof RubyString) {
args[1] = trim(context, doc, (RubyString)args[1]);
if (XmlDocumentFragment.isTag((RubyString)args[1])) {
args[1] = RubyString.newString(context.getRuntime(), addNamespaceDeclIfNeeded(doc, rubyStringToString(args[1])));
}
Expand All @@ -107,18 +105,6 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObj
RuntimeHelpers.invoke(context, fragment, "initialize", args);
return fragment;
}

private static IRubyObject trim(ThreadContext context, XmlDocument xmlDocument, RubyString str) {
// checks whether schema is given. if exists, allows whitespace processing to a parser
Document document = (Document)xmlDocument.node;
if (document.getDoctype() != null) return str;
// strips trailing \n off forcefully
// not to return new object in case of no chomp needed, chomp! is used here.
IRubyObject result;
if (context.getRuntime().is1_9()) result = str.chomp19(context);
else result = str.chomp_bang(context);
return result.isNil() ? str : result;
}

private static boolean isTag(RubyString ruby_string) {
String str = rubyStringToString(ruby_string);
Expand Down
5 changes: 0 additions & 5 deletions test/html/test_document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,6 @@ def test_capturing_nonparse_errors_during_node_copy_between_fragments
assert_equal original_errors1, frag1.errors
assert_equal original_errors2, frag2.errors
end

def test_issue_444_trim_when_no_schem_given
fragment = Nokogiri::HTML::DocumentFragment.parse("<p>hi</p>\n").to_html
assert_equal "<p>hi</p>", fragment
end
end
end
end

0 comments on commit 233571a

Please sign in to comment.