Skip to content

Commit

Permalink
feat: migrate to santuario c14n
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
flavorjones committed Oct 16, 2022
1 parent 7b7b1d5 commit 654f008
Show file tree
Hide file tree
Showing 40 changed files with 64 additions and 5,430 deletions.
2 changes: 2 additions & 0 deletions ext/java/nokogiri/NokogiriService.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class NokogiriService implements BasicLibraryService
createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
createXsltModule(ruby, xsltModule);
nokogiri.setInternalVariable("cache", populateNokogiriClassCahce(ruby));

org.apache.xml.security.Init.init();
}

private void
Expand Down
18 changes: 9 additions & 9 deletions ext/java/nokogiri/XmlDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static nokogiri.internals.NokogiriHelpers.stringOrNil;

import java.util.List;
import java.io.ByteArrayOutputStream;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -36,13 +37,13 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.c14n.Canonicalizer;

import nokogiri.internals.NokogiriHelpers;
import nokogiri.internals.NokogiriNamespaceCache;
import nokogiri.internals.SaveContextVisitor;
import nokogiri.internals.XmlDomParserContext;
import nokogiri.internals.c14n.CanonicalFilter;
import nokogiri.internals.c14n.CanonicalizationException;
import nokogiri.internals.c14n.Canonicalizer;

/**
* Class for Nokogiri::XML::Document
Expand Down Expand Up @@ -673,15 +674,14 @@ private static class DocumentBuilderFactoryHolder
try {
Canonicalizer canonicalizer = Canonicalizer.getInstance(algorithmURI);
XmlNode startingNode = getStartingNode(block);
byte[] result;
CanonicalFilter filter = new CanonicalFilter(context, block);
ByteArrayOutputStream writer = new ByteArrayOutputStream();
if (inclusive_namespace == null) {
result = canonicalizer.canonicalizeSubtree(startingNode.getNode(), filter);
canonicalizer.canonicalizeSubtree(startingNode.getNode(), writer);
} else {
result = canonicalizer.canonicalizeSubtree(startingNode.getNode(), inclusive_namespace, filter);
canonicalizer.canonicalizeSubtree(startingNode.getNode(), inclusive_namespace, writer);
}
return RubyString.newString(context.runtime, new ByteList(result, UTF8Encoding.INSTANCE));
} catch (Exception e) {
return RubyString.newString(context.runtime, writer.toString());
} catch (XMLSecurityException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
}
Expand Down
122 changes: 0 additions & 122 deletions ext/java/nokogiri/internals/c14n/AttrCompare.java

This file was deleted.

178 changes: 0 additions & 178 deletions ext/java/nokogiri/internals/c14n/C14nHelper.java

This file was deleted.

0 comments on commit 654f008

Please sign in to comment.