Skip to content

Commit 9528978

Browse files
committed
feat: migrate to santuario c14n
instead of using a patched fork of apache c14n from 2013 This commit removes the block parameter from the JRuby API, because a) it didn't previously work the same as CRuby/libxml2 (see earlier commit that introduces block test coverage that failed) b) with the mainline c14n library we can't hack it to support even the broken callback semantics and would be forced to implement something complicated ourselves Given I'm not confident that C14n is widely-used anyway, removing a misfeature like this doesn't seem like a controversial decision. So, questions to the JRuby contributors: Q1: Are we OK with all these new dependencies getting pulled in? Q2: There's some Log4J warning messages being emitted at runtime that I'm not sure whether or how to quash. Any ideas?
1 parent b19669c commit 9528978

40 files changed

+58
-5431
lines changed

ext/java/nokogiri/NokogiriService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public class NokogiriService implements BasicLibraryService
9494
createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
9595
createXsltModule(ruby, xsltModule);
9696
nokogiri.setInternalVariable("cache", populateNokogiriClassCahce(ruby));
97+
98+
org.apache.xml.security.Init.init();
9799
}
98100

99101
private void

ext/java/nokogiri/XmlDocument.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static nokogiri.internals.NokogiriHelpers.stringOrNil;
99

1010
import java.util.List;
11+
import java.io.ByteArrayOutputStream;
1112

1213
import javax.xml.parsers.DocumentBuilderFactory;
1314
import javax.xml.parsers.ParserConfigurationException;
@@ -36,13 +37,13 @@
3637
import org.w3c.dom.Node;
3738
import org.w3c.dom.NodeList;
3839

40+
import org.apache.xml.security.exceptions.XMLSecurityException;
41+
import org.apache.xml.security.c14n.Canonicalizer;
42+
3943
import nokogiri.internals.NokogiriHelpers;
4044
import nokogiri.internals.NokogiriNamespaceCache;
4145
import nokogiri.internals.SaveContextVisitor;
4246
import nokogiri.internals.XmlDomParserContext;
43-
import nokogiri.internals.c14n.CanonicalFilter;
44-
import nokogiri.internals.c14n.CanonicalizationException;
45-
import nokogiri.internals.c14n.Canonicalizer;
4647

4748
/**
4849
* Class for Nokogiri::XML::Document
@@ -673,15 +674,14 @@ private static class DocumentBuilderFactoryHolder
673674
try {
674675
Canonicalizer canonicalizer = Canonicalizer.getInstance(algorithmURI);
675676
XmlNode startingNode = getStartingNode(block);
676-
byte[] result;
677-
CanonicalFilter filter = new CanonicalFilter(context, block);
677+
ByteArrayOutputStream writer = new ByteArrayOutputStream();
678678
if (inclusive_namespace == null) {
679-
result = canonicalizer.canonicalizeSubtree(startingNode.getNode(), filter);
679+
canonicalizer.canonicalizeSubtree(startingNode.getNode(), writer);
680680
} else {
681-
result = canonicalizer.canonicalizeSubtree(startingNode.getNode(), inclusive_namespace, filter);
681+
canonicalizer.canonicalizeSubtree(startingNode.getNode(), inclusive_namespace, writer);
682682
}
683-
return RubyString.newString(context.runtime, new ByteList(result, UTF8Encoding.INSTANCE));
684-
} catch (Exception e) {
683+
return RubyString.newString(context.runtime, writer.toString());
684+
} catch (XMLSecurityException e) {
685685
throw context.getRuntime().newRuntimeError(e.getMessage());
686686
}
687687
}

ext/java/nokogiri/internals/c14n/AttrCompare.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

ext/java/nokogiri/internals/c14n/C14nHelper.java

Lines changed: 0 additions & 178 deletions
This file was deleted.

0 commit comments

Comments
 (0)