moxml 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/moxml/adapter/leptris.rb +10 -4
- data/lib/moxml/adapter/libxml.rb +14 -2
- data/lib/moxml/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 566f12c7bcda29e079d0fd5b496a6becff643b9c15afd328d5f99fb7ef70d35c
|
|
4
|
+
data.tar.gz: a4d7858218db7d38300b963b11d5e40b5aec176d2072a177c4e5448f839b8671
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45cf69a5c753718d3bcef44580ef2e8e0dcfa536033537602952e8cbeb73e8bb59e68ad365fdc72c6b7422a998c50e623a1f7b894ed5e7da3cd8e129ff40c703
|
|
7
|
+
data.tar.gz: 0fd18d4891bd29ce56ab1174aa494f8dddc251d298067a0290bf84df41f6854d61bdeedf6e9fd813c32669a9a550419865a637633ddd6e558e84ff0d9f6eca2e
|
|
@@ -546,6 +546,10 @@ module Moxml
|
|
|
546
546
|
# returns those without name accessors). Both engines resolve
|
|
547
547
|
# expression prefixes against document-declared namespaces.
|
|
548
548
|
NATIVE_XPATH_CACHE = XPath::Cache.new(100)
|
|
549
|
+
# The gate decision is expression-intrinsic; re-walking the
|
|
550
|
+
# cached AST three times per xpath call cost ~23% of repeated
|
|
551
|
+
# selective queries, so the boolean caches beside it.
|
|
552
|
+
NATIVE_GATE_CACHE = XPath::Cache.new(100)
|
|
549
553
|
|
|
550
554
|
def xpath(node, expression, namespaces = {})
|
|
551
555
|
native = native_xpath(node, expression, namespaces)
|
|
@@ -623,11 +627,13 @@ module Moxml
|
|
|
623
627
|
# attribute-node results, or the nokogiri-compat xmlns:
|
|
624
628
|
# reserved prefix convention.
|
|
625
629
|
def native_expression?(expression)
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
630
|
+
NATIVE_GATE_CACHE.get_or_set(expression) do
|
|
631
|
+
ast = XPath::Parser.parse_with_cache(expression)
|
|
632
|
+
next false if ast_contains_type?(ast, :variable)
|
|
633
|
+
next false if uses_xmlns_prefix?(ast)
|
|
629
634
|
|
|
630
|
-
|
|
635
|
+
!selects_attribute_results?(ast)
|
|
636
|
+
end
|
|
631
637
|
rescue XPath::SyntaxError
|
|
632
638
|
false
|
|
633
639
|
end
|
data/lib/moxml/adapter/libxml.rb
CHANGED
|
@@ -7,6 +7,11 @@ require "libxml"
|
|
|
7
7
|
module Moxml
|
|
8
8
|
module Adapter
|
|
9
9
|
class Libxml < Base
|
|
10
|
+
# DOCTYPE prolog sniffer; see parse for the index-then-match
|
|
11
|
+
# strategy that keeps this off the hot path.
|
|
12
|
+
DOCTYPE_RE = /<!DOCTYPE\s+([^\s>]+)(?:\s+PUBLIC\s+"([^"]+)"\s+"([^"]+)"|\s+SYSTEM\s+"([^"]+)")?\s*>/i
|
|
13
|
+
private_constant :DOCTYPE_RE
|
|
14
|
+
|
|
10
15
|
autoload :EntityRefRegistry, "moxml/adapter/libxml/entity_ref_registry"
|
|
11
16
|
|
|
12
17
|
# Wrapper class to store DOCTYPE information
|
|
@@ -89,8 +94,15 @@ module Moxml
|
|
|
89
94
|
# parameter or XML declaration for byte interpretation.
|
|
90
95
|
xml_string = preprocess_entities(xml_string)
|
|
91
96
|
|
|
92
|
-
# Extract DOCTYPE before parsing
|
|
93
|
-
|
|
97
|
+
# Extract DOCTYPE before parsing. Locate the literal first:
|
|
98
|
+
# a plain memscan is ~2x cheaper than the regex's literal
|
|
99
|
+
# prefix scan on doctype-less documents (the common case),
|
|
100
|
+
# and matching from the found offset keeps captures
|
|
101
|
+
# identical.
|
|
102
|
+
doctype_idx = xml_string.index("<!DOCTYPE")
|
|
103
|
+
doctype_match = if doctype_idx
|
|
104
|
+
xml_string.match(DOCTYPE_RE, doctype_idx)
|
|
105
|
+
end
|
|
94
106
|
|
|
95
107
|
native_doc = begin
|
|
96
108
|
# Handle both string and file inputs
|
data/lib/moxml/version.rb
CHANGED