schematronium 0.1.0-java → 0.1.4-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e01f9933d9bb8a0c0243986a3d689faead19cfe
4
- data.tar.gz: a95659f5b6b800072daab4a3e6bbda2b564930ef
3
+ metadata.gz: 74beaa03afb2404a3160870d78430983bc61622d
4
+ data.tar.gz: 56a65d7aaadce1887c8d4055e2578903ae7dafbd
5
5
  SHA512:
6
- metadata.gz: 432fa66139ee4a2dbc825b77a8c2438c567e05241e5ff839771898eb7d740849411d2993422c444ca054b5b71c158be5b313fba8268d85cac86b11a21e6ab70c
7
- data.tar.gz: 62dac2298331473194d1646401f6ffd27ff10e3ec317b4088cbb3c15aee401d2a269ad4d56791c1a736914a2f91d8cbb498053e2fb8dbcfe62692eeb7559143e
6
+ metadata.gz: 97e89b77ba28e47f438ed80c7b4ea34f61c6d2c5af43610b09f79d8c12c13444d276d7f35ba5fb8ebbd0f125465b8d50f61f41790e10506112dd6c84aace5457
7
+ data.tar.gz: b0212f6ef6a938ccab58f9dc142181a36406fb5bc57ea7db8e501f4106cba012b4c612180fbf44ca5a7bf8bc4348b7d58d3cdd4684748a6dd9c2548a07ec7e82
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Schematronium is a gem providing:
4
4
 
5
5
  1. A single-object, single-function API for compiling a [schematron](http://www.schematron.com/) script, and running it over an XML file, returning a [Nokogiri](Nokogiri.org) [NodeSet](http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/NodeSet) of the resulting `failed-assert`s and `successful-report`s.
6
- 2. A script ([schematronium](bin/schematronium)) to run a schematron over one or many XML files and return aggregate date in a TBD format. Mostly meant as an example of something you could to with it.
6
+ 2. A script ([schematronium](bin/schematronium)) to run a schematron over one or many XML files and return aggregate date in a TBD format. Mostly meant as an example of something you could to with it. Also shows how to turn off some parser features to prevent XXE vulnerabilities, which is VERY IMPORTANT if you are parsing XML you do not personally 100% control. Schematronium does NOT do this by default.
7
7
 
8
8
  The goals of Schematronium are very similar to [schematron-wrapper](https://github.com/Agilefreaks/schematron-wrapper). The primary difference is that, where schematron-wrapper runs the saxon jar via backticks per file, Schematronium uses the jRuby-only [saxon-xslt](https://github.com/fidothe/saxon-xslt) library to compile and run the schematron. This has the upshot of not incurring the penalty of JDK initialization per file, which tends to be a substantial cost savings over even a small number of files.
9
9
 
data/bin/schematronium CHANGED
@@ -6,6 +6,14 @@ raise "Not enough arguments" if ARGV.length < 2
6
6
 
7
7
  Saxon::Processor.default.config[:line_numbering] = true
8
8
 
9
+ # Disable a bunch of stuff in parser to prevent XXE vulnerabilities
10
+ parser_options = Saxon::Processor.default.to_java.getUnderlyingConfiguration.parseOptions
11
+ parser_options.add_parser_feature("http://apache.org/xml/features/disallow-doctype-decl", true)
12
+ parser_options.add_parser_feature("http://xml.org/sax/features/external-general-entities", false)
13
+ parser_options.add_parser_feature("http://xml.org/sax/features/external-parameter-entities", false)
14
+
15
+
16
+
9
17
  stron = Schematronium.new(ARGV.shift)
10
18
 
11
19
  @fnames = []
@@ -14,14 +22,11 @@ if ARGV.empty?
14
22
  @fnames = @fnames + Dir[File.join('.', "*.xml")]
15
23
  else
16
24
  ARGV.each do |arg|
17
- # Because absolute_path doesn't work right? Investigate
18
- arg = arg.sub(/~/, Dir.home)
19
-
20
- @fnames += case File.absolute_path(arg)
25
+ @fnames += case File.expand_path(arg)
21
26
  when File.method(:directory?).to_proc
22
- Dir[File.join(File.absolute_path(arg), "*.xml")]
27
+ Dir[File.join(File.expand_path(arg), "*.xml")]
23
28
  when File.method(:file?).to_proc
24
- [File.absolute_path(arg)]
29
+ [File.expand_path(arg)]
25
30
  else
26
31
  []
27
32
  end
@@ -35,7 +40,7 @@ puts '<?xml version="1.0" encoding="UTF-8"?><files>'
35
40
  xml = stron.check(s_xml)
36
41
  xml.remove_namespaces!
37
42
 
38
- xml = xml.xpath("//*[self::failed-assert or self::successful-report]")
43
+ xml = xml.xpath("//failed-assert|//successful-report")
39
44
  xml.each do |el|
40
45
  el["line-number"] = s_xml.xpath(el.attr("location")).get_line_number
41
46
  end
data/lib/schematronium.rb CHANGED
@@ -14,15 +14,16 @@ class Schematronium
14
14
  iso_abstract_expand.xsl
15
15
  iso_svrl_for_xslt2.xsl|.map{|s| iso_file s}
16
16
 
17
- schematron = case schematron
18
- when IO
17
+ schematron = if schematron.respond_to? :read
19
18
  Saxon.XML(schematron.read)
20
- when String
19
+ elsif schematron.kind_of? String
21
20
  if File.file? schematron
22
21
  Saxon.XML(File.open(schematron))
23
22
  else
24
23
  Saxon.XML(schematron)
25
24
  end
25
+ else
26
+ raise "Unable to generate Schematron document from #{schematron.class.to_s}"
26
27
  end
27
28
 
28
29
  # Run schematron through each stage of the iso_schematron pipeline
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'schematronium'
3
- gem.version = '0.1.0'
3
+ gem.version = '0.1.4'
4
4
  gem.date = '2015-07-27'
5
5
  gem.summary = 'Tool for running schematron against XML strings/files'
6
6
  gem.description = 'Wraps the saxon-xslt wrapper for Saxon 9 HE, providing a simple (one function) interface for running a schematron against an XML string or file'
@@ -22,5 +22,4 @@ Gem::Specification.new do |gem|
22
22
 
23
23
  gem.add_development_dependency "rake", '~> 10.4'
24
24
  gem.add_development_dependency "minitest"
25
-
26
25
  end
@@ -1,6 +1,9 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
3
- <pattern>
3
+ <phase id="testphase">
4
+ <active pattern="b" />
5
+ </phase>
6
+ <pattern id="a">
4
7
  <rule context="*:test">
5
8
  <report test="*:testable">
6
9
  There should be 'testable' elements within 'test's.
@@ -9,5 +12,10 @@
9
12
  <rule context="*:test/*:testable">
10
13
  <assert test="@test-attr">Testables must have have the 'test-attr' attribute.</assert>
11
14
  </rule>
12
- </pattern>
15
+ </pattern>
16
+ <pattern id="b">
17
+ <rule context="*:test[1]">
18
+ <assert test="@test-attr">Testables must have have the 'test-attr' attribute.</assert>
19
+ </rule>
20
+ </pattern>
13
21
  </schema>
@@ -8,15 +8,18 @@ class SchematroniumTest < MiniTest::Test
8
8
  File.join(File.expand_path(File.dirname(__FILE__)), 'test_data', *path_segments)
9
9
  end
10
10
 
11
- def setup
12
- @stron = Schematronium.new(td('schematron', 'test.sch'))
13
- end
14
-
15
11
  def test_check_with_file
16
- results = @stron.check(File.open(td('xml', 'test.xml')))
12
+ stron = Schematronium.new(td('schematron', 'test.sch'))
13
+ results = stron.check(File.open(td('xml', 'test.xml')))
17
14
  results.remove_namespaces!
18
- assert_equal 1, results.xpath("//failed-assert").count, "Expects one failure"
15
+ assert_equal 2, results.xpath("//failed-assert").count, "Expects two failures"
19
16
  assert_equal 2, results.xpath("//successful-report").count, "Expects two reports"
20
17
  end
21
18
 
19
+ def test_check_with_phase
20
+ stron = Schematronium.new(td('schematron', 'test.sch'), "'testphase'")
21
+ results = stron.check(File.open(td('xml', 'test.xml')))
22
+ results.remove_namespaces!
23
+ assert_equal 1, results.xpath("//failed-assert").count, "Expects one failure"
24
+ end
22
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schematronium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: java
6
6
  authors:
7
7
  - Dave Mayo
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.4.6
122
+ rubygems_version: 2.4.8
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Tool for running schematron against XML strings/files