From b0db2a7fa12946172f5c3aad86905d06958ab2b5 Mon Sep 17 00:00:00 2001 From: Patrick Cheng Date: Fri, 16 Nov 2012 14:54:05 -0800 Subject: [PATCH] Fixed issue found while try to troubleshoot ruby-saml with jruby when XSD has DOCTYPE to DTD, not able to load the file. and the ruby script is run without path, NullPointerException got thrown. Test to demostrate https://github.com/sparklemotion/nokogiri/pull/791 --- ext/java/nokogiri/XmlSchema.java | 2 +- .../nokogiri/internals/NokogiriHelpers.java | 1 + test/files/saml/saml20assertion_schema.xsd | 283 ++++++++++++++++ test/files/saml/saml20protocol_schema.xsd | 302 +++++++++++++++++ test/files/saml/xenc_schema.xsd | 146 ++++++++ test/files/saml/xmldsig_schema.xsd | 318 ++++++++++++++++++ test/xml/test_schema.rb | 9 + 7 files changed, 1060 insertions(+), 1 deletion(-) create mode 100644 test/files/saml/saml20assertion_schema.xsd create mode 100644 test/files/saml/saml20protocol_schema.xsd create mode 100644 test/files/saml/xenc_schema.xsd create mode 100644 test/files/saml/xmldsig_schema.xsd diff --git a/ext/java/nokogiri/XmlSchema.java b/ext/java/nokogiri/XmlSchema.java index 6064bf14ea..9ed3c2e15c 100644 --- a/ext/java/nokogiri/XmlSchema.java +++ b/ext/java/nokogiri/XmlSchema.java @@ -224,7 +224,7 @@ private class SchemaResourceResolver implements LSResourceResolver { public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { String adjusted = adjustSystemIdIfNecessary(currentDir, scriptFileName, baseURI, systemId); lsInput.setPublicId(publicId); - lsInput.setSystemId(adjusted); + lsInput.setSystemId(adjusted != null? adjusted : systemId); lsInput.setBaseURI(baseURI); return lsInput; } diff --git a/ext/java/nokogiri/internals/NokogiriHelpers.java b/ext/java/nokogiri/internals/NokogiriHelpers.java index e05d190478..ed48177c54 100644 --- a/ext/java/nokogiri/internals/NokogiriHelpers.java +++ b/ext/java/nokogiri/internals/NokogiriHelpers.java @@ -713,6 +713,7 @@ private static String resolveSystemId(String baseName, String systemId) { File base = new File(baseName); if (base.isDirectory()) parentName = baseName; else parentName = base.getParent(); + if (parentName == null) return null; if (parentName.toLowerCase().startsWith("file:")) parentName = parentName.substring("file:".length()); File dtdFile = new File(parentName + "/" + systemId); if (dtdFile.exists()) return dtdFile.getPath(); diff --git a/test/files/saml/saml20assertion_schema.xsd b/test/files/saml/saml20assertion_schema.xsd new file mode 100644 index 0000000000..ee6c77026a --- /dev/null +++ b/test/files/saml/saml20assertion_schema.xsd @@ -0,0 +1,283 @@ + + + + + + + Document identifier: saml-schema-assertion-2.0 + Location: http://docs.oasis-open.org/security/saml/v2.0/ + Revision history: + V1.0 (November, 2002): + Initial Standard Schema. + V1.1 (September, 2003): + Updates within the same V1.0 namespace. + V2.0 (March, 2005): + New assertion schema for SAML V2.0 namespace. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/files/saml/saml20protocol_schema.xsd b/test/files/saml/saml20protocol_schema.xsd new file mode 100644 index 0000000000..5e351a0aab --- /dev/null +++ b/test/files/saml/saml20protocol_schema.xsd @@ -0,0 +1,302 @@ + + + + + + + Document identifier: saml-schema-protocol-2.0 + Location: http://docs.oasis-open.org/security/saml/v2.0/ + Revision history: + V1.0 (November, 2002): + Initial Standard Schema. + V1.1 (September, 2003): + Updates within the same V1.0 namespace. + V2.0 (March, 2005): + New protocol schema based in a SAML V2.0 namespace. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/files/saml/xenc_schema.xsd b/test/files/saml/xenc_schema.xsd new file mode 100644 index 0000000000..1990a6d8e2 --- /dev/null +++ b/test/files/saml/xenc_schema.xsd @@ -0,0 +1,146 @@ + + + + + + ]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/files/saml/xmldsig_schema.xsd b/test/files/saml/xmldsig_schema.xsd new file mode 100644 index 0000000000..df126b30e6 --- /dev/null +++ b/test/files/saml/xmldsig_schema.xsd @@ -0,0 +1,318 @@ + + + + + + ]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/xml/test_schema.rb b/test/xml/test_schema.rb index a43ac1dcdb..11fb05d558 100644 --- a/test/xml/test_schema.rb +++ b/test/xml/test_schema.rb @@ -89,6 +89,15 @@ def test_valid? assert(@xsd.valid?(valid_doc)) assert(!@xsd.valid?(invalid_doc)) end + + def test_xsd_with_dtd + Dir.chdir(File.join(ASSETS_DIR, 'saml')) do + # works + Nokogiri::XML::Schema(IO.read('xmldsig_schema.xsd')) + # was not working + Nokogiri::XML::Schema(IO.read('saml20protocol_schema.xsd')) + end + end end end end