nokogiri 1.6.1 → 1.6.2.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (93) hide show
  1. checksums.yaml +7 -7
  2. data/.editorconfig +17 -0
  3. data/.travis.yml +4 -6
  4. data/CHANGELOG.ja.rdoc +37 -8
  5. data/CHANGELOG.rdoc +48 -3
  6. data/Gemfile +3 -3
  7. data/Manifest.txt +57 -1
  8. data/README.ja.rdoc +22 -16
  9. data/README.rdoc +24 -19
  10. data/ROADMAP.md +1 -2
  11. data/Rakefile +161 -58
  12. data/build_all +56 -31
  13. data/dependencies.yml +3 -3
  14. data/ext/nokogiri/extconf.rb +379 -121
  15. data/ext/nokogiri/html_document.c +2 -2
  16. data/ext/nokogiri/nokogiri.c +6 -1
  17. data/ext/nokogiri/xml_document.c +5 -4
  18. data/ext/nokogiri/xml_node.c +11 -4
  19. data/ext/nokogiri/xml_reader.c +1 -1
  20. data/ext/nokogiri/xml_sax_parser_context.c +40 -0
  21. data/ext/nokogiri/xml_syntax_error.c +10 -5
  22. data/ext/nokogiri/xml_syntax_error.h +1 -1
  23. data/ext/nokogiri/xml_xpath_context.c +2 -14
  24. data/ext/nokogiri/xslt_stylesheet.c +1 -1
  25. data/lib/nokogiri.rb +31 -22
  26. data/lib/nokogiri/css/node.rb +0 -50
  27. data/lib/nokogiri/css/parser.rb +213 -218
  28. data/lib/nokogiri/css/parser.y +21 -30
  29. data/lib/nokogiri/css/xpath_visitor.rb +62 -14
  30. data/lib/nokogiri/html/document.rb +97 -18
  31. data/lib/nokogiri/html/sax/parser.rb +2 -2
  32. data/lib/nokogiri/version.rb +1 -1
  33. data/lib/nokogiri/xml/builder.rb +1 -1
  34. data/lib/nokogiri/xml/document.rb +2 -2
  35. data/lib/nokogiri/xml/dtd.rb +10 -0
  36. data/lib/nokogiri/xml/node.rb +26 -1
  37. data/lib/nokogiri/xml/sax/parser.rb +1 -1
  38. data/ports/archives/libxslt-1.1.28.tar.gz +0 -0
  39. data/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch +265 -0
  40. data/ports/patches/libxml2/0002-Fix-entities-local-buffers-size-problems.patch +102 -0
  41. data/ports/patches/libxml2/0003-Fix-an-error-in-previous-commit.patch +26 -0
  42. data/ports/patches/libxml2/0004-Fix-potential-out-of-bound-access.patch +26 -0
  43. data/ports/patches/libxml2/0005-Detect-excessive-entities-expansion-upon-replacement.patch +158 -0
  44. data/ports/patches/libxml2/0006-Do-not-fetch-external-parsed-entities.patch +78 -0
  45. data/ports/patches/libxml2/0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch +480 -0
  46. data/ports/patches/libxml2/0008-Improve-handling-of-xmlStopParser.patch +315 -0
  47. data/ports/patches/libxml2/0009-Fix-a-couple-of-return-without-value.patch +37 -0
  48. data/ports/patches/libxslt/0001-Adding-doc-update-related-to-1.1.28.patch +222 -0
  49. data/ports/patches/libxslt/0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch +53 -0
  50. data/ports/patches/libxslt/0003-Initialize-pseudo-random-number-generator-with-curre.patch +60 -0
  51. data/ports/patches/libxslt/0004-EXSLT-function-str-replace-is-broken-as-is.patch +42 -0
  52. data/ports/patches/libxslt/0006-Fix-str-padding-to-work-with-UTF-8-strings.patch +164 -0
  53. data/ports/patches/libxslt/0007-Separate-function-for-predicate-matching-in-patterns.patch +587 -0
  54. data/ports/patches/libxslt/0008-Fix-direct-pattern-matching.patch +80 -0
  55. data/ports/patches/libxslt/0009-Fix-certain-patterns-with-predicates.patch +185 -0
  56. data/ports/patches/libxslt/0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch +126 -0
  57. data/ports/patches/libxslt/0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch +25 -0
  58. data/ports/patches/libxslt/0014-Fix-for-bug-436589.patch +43 -0
  59. data/ports/patches/libxslt/0015-Fix-mkdir-for-mingw.patch +41 -0
  60. data/suppressions/README.txt +1 -0
  61. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  62. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  63. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  64. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  65. data/test/css/test_nthiness.rb +65 -2
  66. data/test/css/test_parser.rb +27 -10
  67. data/test/css/test_tokenizer.rb +1 -1
  68. data/test/css/test_xpath_visitor.rb +6 -1
  69. data/test/files/atom.xml +344 -0
  70. data/test/files/shift_jis_no_charset.html +9 -0
  71. data/test/helper.rb +10 -0
  72. data/test/html/test_document.rb +74 -7
  73. data/test/html/test_document_encoding.rb +10 -0
  74. data/test/html/test_document_fragment.rb +3 -3
  75. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  76. data/test/test_nokogiri.rb +6 -0
  77. data/test/test_reader.rb +7 -4
  78. data/test/test_xslt_transforms.rb +25 -0
  79. data/test/xml/sax/test_parser.rb +16 -0
  80. data/test/xml/sax/test_parser_context.rb +9 -0
  81. data/test/xml/test_builder.rb +9 -0
  82. data/test/xml/test_c14n.rb +12 -2
  83. data/test/xml/test_document.rb +66 -0
  84. data/test/xml/test_document_fragment.rb +5 -0
  85. data/test/xml/test_dtd.rb +84 -0
  86. data/test/xml/test_entity_reference.rb +3 -3
  87. data/test/xml/test_node.rb +21 -3
  88. data/test/xml/test_node_attributes.rb +17 -0
  89. data/test/xml/test_schema.rb +26 -0
  90. data/test/xml/test_xpath.rb +81 -0
  91. metadata +254 -174
  92. data/ports/archives/libxslt-1.1.26.tar.gz +0 -0
  93. data/tasks/cross_compile.rb +0 -134
@@ -0,0 +1,53 @@
1
+ From 90e8b9066d877e040e791bbf206db0e5653e017a Mon Sep 17 00:00:00 2001
2
+ From: Daniel Veillard <veillard@redhat.com>
3
+ Date: Wed, 30 Jan 2013 17:31:37 +0100
4
+ Subject: [PATCH 02/14] Fix a couple of places where (f)printf parameters were
5
+ broken
6
+
7
+ As reported by Thomas Jarosch <thomas.jarosch@intra2net.com>
8
+ ---
9
+ python/libxslt.c | 10 +++++-----
10
+ xsltproc/xsltproc.c | 2 +-
11
+ 2 files changed, 6 insertions(+), 6 deletions(-)
12
+
13
+ diff --git a/python/libxslt.c b/python/libxslt.c
14
+ index 6a4f1c3..8dd6c78 100644
15
+ --- a/python/libxslt.c
16
+ +++ b/python/libxslt.c
17
+ @@ -356,15 +356,15 @@ libxslt_xsltRegisterExtModuleElement(PyObject *self ATTRIBUTE_UNUSED,
18
+ PyObject *pyobj_element_f;
19
+ PyObject *pyobj_precomp_f;
20
+
21
+ -#ifdef DEBUG_EXTENSIONS
22
+ - printf("libxslt_xsltRegisterExtModuleElement called\n",
23
+ - name, ns_uri);
24
+ -#endif
25
+ -
26
+ if (!PyArg_ParseTuple(args, (char *)"szOO:registerExtModuleElement",
27
+ &name, &ns_uri, &pyobj_precomp_f, &pyobj_element_f))
28
+ return(NULL);
29
+
30
+ +#ifdef DEBUG_EXTENSIONS
31
+ + printf("libxslt_xsltRegisterExtModuleElement called: %s %s\n",
32
+ + name, ns_uri);
33
+ +#endif
34
+ +
35
+ if ((name == NULL) || (pyobj_element_f == NULL) || (pyobj_precomp_f == NULL)) {
36
+ py_retval = libxml_intWrap(-1);
37
+ return(py_retval);
38
+ diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c
39
+ index 35f37e8..dfd6d31 100644
40
+ --- a/xsltproc/xsltproc.c
41
+ +++ b/xsltproc/xsltproc.c
42
+ @@ -319,7 +319,7 @@ static void endTimer(char *format, ...)
43
+ va_start(ap, format);
44
+ vfprintf(stderr,format,ap);
45
+ va_end(ap);
46
+ - fprintf(stderr, " was not timed\n", msec);
47
+ + fprintf(stderr, " was not timed\n");
48
+ #else
49
+ /* We don't have gettimeofday, time or stdarg.h, what crazy world is
50
+ * this ?!
51
+ --
52
+ 1.8.4.1
53
+
@@ -0,0 +1,60 @@
1
+ From 3fcf11ead6ad226227b0a3ef4cc6565b8d5857ff Mon Sep 17 00:00:00 2001
2
+ From: Nils Werner <wernerns@iis.fraunhofer.de>
3
+ Date: Thu, 24 Jan 2013 19:44:03 +0100
4
+ Subject: [PATCH 03/14] Initialize pseudo random number generator with current
5
+ time or optional command line parameter
6
+
7
+ ---
8
+ xsltproc/xsltproc.c | 15 +++++++++++++++
9
+ 1 file changed, 15 insertions(+)
10
+
11
+ diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c
12
+ index dfd6d31..45adf5d 100644
13
+ --- a/xsltproc/xsltproc.c
14
+ +++ b/xsltproc/xsltproc.c
15
+ @@ -514,6 +514,7 @@ static void usage(const char *name) {
16
+ printf("\t--maxdepth val : increase the maximum depth (default %d)\n", xsltMaxDepth);
17
+ printf("\t--maxvars val : increase the maximum variables (default %d)\n", xsltMaxVars);
18
+ printf("\t--maxparserdepth val : increase the maximum parser depth\n");
19
+ + printf("\t--seed-rand val : initialize pseudo random number generator with specific seed\n");
20
+ #ifdef LIBXML_HTML_ENABLED
21
+ printf("\t--html: the input document is(are) an HTML file(s)\n");
22
+ #endif
23
+ @@ -556,6 +557,7 @@ main(int argc, char **argv)
24
+ return (1);
25
+ }
26
+
27
+ + srand(time(NULL));
28
+ xmlInitMemory();
29
+
30
+ LIBXML_TEST_VERSION
31
+ @@ -750,6 +752,15 @@ main(int argc, char **argv)
32
+ if (value > 0)
33
+ xmlParserMaxDepth = value;
34
+ }
35
+ + } else if ((!strcmp(argv[i], "-seed-rand")) ||
36
+ + (!strcmp(argv[i], "--seed-rand"))) {
37
+ + int value;
38
+ +
39
+ + i++;
40
+ + if (sscanf(argv[i], "%d", &value) == 1) {
41
+ + if (value > 0)
42
+ + srand(value);
43
+ + }
44
+ } else if ((!strcmp(argv[i],"-dumpextensions"))||
45
+ (!strcmp(argv[i],"--dumpextensions"))) {
46
+ dumpextensions++;
47
+ @@ -786,6 +797,10 @@ main(int argc, char **argv)
48
+ (!strcmp(argv[i], "--maxparserdepth"))) {
49
+ i++;
50
+ continue;
51
+ + } else if ((!strcmp(argv[i], "-seed-rand")) ||
52
+ + (!strcmp(argv[i], "--seed-rand"))) {
53
+ + i++;
54
+ + continue;
55
+ } else if ((!strcmp(argv[i], "-o")) ||
56
+ (!strcmp(argv[i], "-output")) ||
57
+ (!strcmp(argv[i], "--output"))) {
58
+ --
59
+ 1.8.4.1
60
+
@@ -0,0 +1,42 @@
1
+ From ae49d7a73b043bccb7631e7d9577bcaa0bbf8528 Mon Sep 17 00:00:00 2001
2
+ From: Nick Wellnhofer <wellnhofer@aevum.de>
3
+ Date: Mon, 1 Jul 2013 21:10:10 +0800
4
+ Subject: [PATCH 04/14] EXSLT function str:replace() is broken as-is
5
+
6
+ the str:replace() function is no longer usable without a transform
7
+ context. I take it from the bug report that it is not supposed to be used
8
+ from plain XPath but only from XSLT according to the EXSLT specification.
9
+
10
+ However, the previous implementation used to work in XPath and is still
11
+ registered on an xmlXPathContext by the exsltStrXpathCtxtRegister()
12
+ function. When called from plain XPath, it results in a memory error in
13
+ line 526 (exsltStrReturnString()) of strings.c because xsltCreateRVT()
14
+ returns NULL as an error indicator due to a NULL transform context being
15
+ passed in, which was the return value from xsltXPathGetTransformContext() a
16
+ bit further up (and the code doesn't validate that).
17
+
18
+ Since fixing the function looks impossible, best is to remove it.
19
+ ---
20
+ libexslt/strings.c | 6 +-----
21
+ 1 file changed, 1 insertion(+), 5 deletions(-)
22
+
23
+ diff --git a/libexslt/strings.c b/libexslt/strings.c
24
+ index 045cc14..c0c7a18 100644
25
+ --- a/libexslt/strings.c
26
+ +++ b/libexslt/strings.c
27
+ @@ -838,11 +838,7 @@ exsltStrXpathCtxtRegister (xmlXPathContextPtr ctxt, const xmlChar *prefix)
28
+ && !xmlXPathRegisterFuncNS(ctxt,
29
+ (const xmlChar *) "concat",
30
+ (const xmlChar *) EXSLT_STRINGS_NAMESPACE,
31
+ - exsltStrConcatFunction)
32
+ - && !xmlXPathRegisterFuncNS(ctxt,
33
+ - (const xmlChar *) "replace",
34
+ - (const xmlChar *) EXSLT_STRINGS_NAMESPACE,
35
+ - exsltStrReplaceFunction)) {
36
+ + exsltStrConcatFunction)) {
37
+ return 0;
38
+ }
39
+ return -1;
40
+ --
41
+ 1.8.4.1
42
+
@@ -0,0 +1,164 @@
1
+ From 515283959aae470a6ee5033deb9f977a489e7578 Mon Sep 17 00:00:00 2001
2
+ From: Nick Wellnhofer <wellnhofer@aevum.de>
3
+ Date: Sun, 4 Aug 2013 16:42:51 +0200
4
+ Subject: [PATCH 06/14] Fix str:padding to work with UTF-8 strings
5
+
6
+ Thanks to Tobias Hoffmann for the report.
7
+
8
+ Also add some tests.
9
+ ---
10
+ libexslt/strings.c | 16 +++++++++-------
11
+ tests/exslt/strings/padding.1.out | 27 ++++++++++++++++++++++++++
12
+ tests/exslt/strings/padding.1.xml | 10 ++++++++++
13
+ tests/exslt/strings/padding.1.xsl | 40 +++++++++++++++++++++++++++++++++++++++
14
+ 4 files changed, 86 insertions(+), 7 deletions(-)
15
+ create mode 100644 tests/exslt/strings/padding.1.out
16
+ create mode 100644 tests/exslt/strings/padding.1.xml
17
+ create mode 100644 tests/exslt/strings/padding.1.xsl
18
+
19
+ diff --git a/libexslt/strings.c b/libexslt/strings.c
20
+ index c0c7a18..3c702ad 100644
21
+ --- a/libexslt/strings.c
22
+ +++ b/libexslt/strings.c
23
+ @@ -351,8 +351,8 @@ exsltStrDecodeUriFunction (xmlXPathParserContextPtr ctxt, int nargs) {
24
+ */
25
+ static void
26
+ exsltStrPaddingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
27
+ - int number, str_len = 0;
28
+ - xmlChar *str = NULL, *ret = NULL, *tmp;
29
+ + int number, str_len = 0, str_size = 0;
30
+ + xmlChar *str = NULL, *ret = NULL;
31
+
32
+ if ((nargs < 1) || (nargs > 2)) {
33
+ xmlXPathSetArityError(ctxt);
34
+ @@ -362,11 +362,13 @@ exsltStrPaddingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
35
+ if (nargs == 2) {
36
+ str = xmlXPathPopString(ctxt);
37
+ str_len = xmlUTF8Strlen(str);
38
+ + str_size = xmlStrlen(str);
39
+ }
40
+ if (str_len == 0) {
41
+ if (str != NULL) xmlFree(str);
42
+ str = xmlStrdup((const xmlChar *) " ");
43
+ str_len = 1;
44
+ + str_size = 1;
45
+ }
46
+
47
+ number = (int) xmlXPathPopNumber(ctxt);
48
+ @@ -378,13 +380,13 @@ exsltStrPaddingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
49
+ }
50
+
51
+ while (number >= str_len) {
52
+ - ret = xmlStrncat(ret, str, str_len);
53
+ + ret = xmlStrncat(ret, str, str_size);
54
+ number -= str_len;
55
+ }
56
+ - tmp = xmlUTF8Strndup (str, number);
57
+ - ret = xmlStrcat(ret, tmp);
58
+ - if (tmp != NULL)
59
+ - xmlFree (tmp);
60
+ + if (number > 0) {
61
+ + str_size = xmlUTF8Strsize(str, number);
62
+ + ret = xmlStrncat(ret, str, str_size);
63
+ + }
64
+
65
+ xmlXPathReturnString(ctxt, ret);
66
+
67
+ diff --git a/tests/exslt/strings/padding.1.out b/tests/exslt/strings/padding.1.out
68
+ new file mode 100644
69
+ index 0000000..1833a65
70
+ --- /dev/null
71
+ +++ b/tests/exslt/strings/padding.1.out
72
+ @@ -0,0 +1,27 @@
73
+ +<?xml version="1.0"?>
74
+ +<test-results>
75
+ + <test-result>
76
+ + <padding> </padding>
77
+ + <length-check>OK</length-check>
78
+ + </test-result>
79
+ + <test-result>
80
+ + <padding>--------</padding>
81
+ + <length-check>OK</length-check>
82
+ + </test-result>
83
+ + <test-result>
84
+ + <padding>abcabcabca</padding>
85
+ + <length-check>OK</length-check>
86
+ + </test-result>
87
+ + <test-result>
88
+ + <padding>–––––––</padding>
89
+ + <length-check>OK</length-check>
90
+ + </test-result>
91
+ + <test-result>
92
+ + <padding>– – – – – –</padding>
93
+ + <length-check>OK</length-check>
94
+ + </test-result>
95
+ + <test-result>
96
+ + <padding>ÄÖÜÄÖÜ</padding>
97
+ + <length-check>OK</length-check>
98
+ + </test-result>
99
+ +</test-results>
100
+ diff --git a/tests/exslt/strings/padding.1.xml b/tests/exslt/strings/padding.1.xml
101
+ new file mode 100644
102
+ index 0000000..16d0824
103
+ --- /dev/null
104
+ +++ b/tests/exslt/strings/padding.1.xml
105
+ @@ -0,0 +1,10 @@
106
+ +<?xml version="1.0"?>
107
+ +<test-cases>
108
+ + <test-case length="5"/>
109
+ + <test-case length="8">-</test-case>
110
+ + <test-case length="10">abc</test-case>
111
+ + <test-case length="7">&#x2013;</test-case>
112
+ + <test-case length="11">&#x2013;&#xa0;</test-case>
113
+ + <test-case length="6">ÄÖÜ</test-case>
114
+ +</test-cases>
115
+ +
116
+ diff --git a/tests/exslt/strings/padding.1.xsl b/tests/exslt/strings/padding.1.xsl
117
+ new file mode 100644
118
+ index 0000000..c5d621d
119
+ --- /dev/null
120
+ +++ b/tests/exslt/strings/padding.1.xsl
121
+ @@ -0,0 +1,40 @@
122
+ +<?xml version="1.0"?>
123
+ +<xsl:stylesheet version="1.0"
124
+ + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
125
+ + xmlns:str="http://exslt.org/strings"
126
+ + exclude-result-prefixes="str">
127
+ +
128
+ +<xsl:output indent="yes"/>
129
+ +
130
+ +<xsl:template match="test-cases">
131
+ + <test-results>
132
+ + <xsl:apply-templates select="test-case"/>
133
+ + </test-results>
134
+ +</xsl:template>
135
+ +
136
+ +<xsl:template match="test-case">
137
+ + <test-result>
138
+ + <xsl:variable name="padding">
139
+ + <xsl:choose>
140
+ + <xsl:when test="string(.)">
141
+ + <xsl:value-of select="str:padding(@length, .)"/>
142
+ + </xsl:when>
143
+ + <xsl:otherwise>
144
+ + <xsl:value-of select="str:padding(@length)"/>
145
+ + </xsl:otherwise>
146
+ + </xsl:choose>
147
+ + </xsl:variable>
148
+ + <padding>
149
+ + <xsl:value-of select="$padding"/>
150
+ + </padding>
151
+ + <length-check>
152
+ + <xsl:choose>
153
+ + <xsl:when test="string-length($padding) = @length">OK</xsl:when>
154
+ + <xsl:otherwise>FAIL</xsl:otherwise>
155
+ + </xsl:choose>
156
+ + </length-check>
157
+ + </test-result>
158
+ +</xsl:template>
159
+ +
160
+ +</xsl:stylesheet>
161
+ +
162
+ --
163
+ 1.8.4.1
164
+
@@ -0,0 +1,587 @@
1
+ From a0116212e6dde5efe311e8240e45ae1477f8988f Mon Sep 17 00:00:00 2001
2
+ From: Nick Wellnhofer <wellnhofer@aevum.de>
3
+ Date: Sun, 4 Aug 2013 20:28:19 +0200
4
+ Subject: [PATCH 07/14] Separate function for predicate matching in patterns
5
+
6
+ No functional change, only make the predicate matching code more
7
+ readable.
8
+ ---
9
+ libxslt/pattern.c | 546 +++++++++++++++++++++++++++---------------------------
10
+ 1 file changed, 274 insertions(+), 272 deletions(-)
11
+
12
+ diff --git a/libxslt/pattern.c b/libxslt/pattern.c
13
+ index 63ec25a..414363b 100644
14
+ --- a/libxslt/pattern.c
15
+ +++ b/libxslt/pattern.c
16
+ @@ -621,6 +621,278 @@ xsltTestCompMatchDirect(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp,
17
+ }
18
+
19
+ /**
20
+ + * xsltTestPredicateMatch:
21
+ + * @ctxt: a XSLT process context
22
+ + * @comp: the precompiled pattern
23
+ + * @node: a node
24
+ + * @step: the predicate step
25
+ + * @sel: the previous step
26
+ + *
27
+ + * Test whether the node matches the predicate
28
+ + *
29
+ + * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure
30
+ + */
31
+ +static int
32
+ +xsltTestPredicateMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp,
33
+ + xmlNodePtr node, xsltStepOpPtr step,
34
+ + xsltStepOpPtr sel) {
35
+ + xmlNodePtr oldNode;
36
+ + xmlDocPtr doc;
37
+ + int oldCS, oldCP;
38
+ + int pos = 0, len = 0;
39
+ + int isRVT;
40
+ + int match;
41
+ +
42
+ + if (step->value == NULL)
43
+ + return(0);
44
+ + if (step->comp == NULL)
45
+ + return(0);
46
+ +
47
+ + doc = node->doc;
48
+ + if (XSLT_IS_RES_TREE_FRAG(doc))
49
+ + isRVT = 1;
50
+ + else
51
+ + isRVT = 0;
52
+ +
53
+ + /*
54
+ + * Depending on the last selection, one may need to
55
+ + * recompute contextSize and proximityPosition.
56
+ + */
57
+ + oldCS = ctxt->xpathCtxt->contextSize;
58
+ + oldCP = ctxt->xpathCtxt->proximityPosition;
59
+ + if ((sel != NULL) &&
60
+ + (sel->op == XSLT_OP_ELEM) &&
61
+ + (sel->value != NULL) &&
62
+ + (node->type == XML_ELEMENT_NODE) &&
63
+ + (node->parent != NULL)) {
64
+ + xmlNodePtr previous;
65
+ + int nocache = 0;
66
+ +
67
+ + previous = (xmlNodePtr)
68
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
69
+ + if ((previous != NULL) &&
70
+ + (previous->parent == node->parent)) {
71
+ + /*
72
+ + * just walk back to adjust the index
73
+ + */
74
+ + int indx = 0;
75
+ + xmlNodePtr sibling = node;
76
+ +
77
+ + while (sibling != NULL) {
78
+ + if (sibling == previous)
79
+ + break;
80
+ + if ((sibling->type == XML_ELEMENT_NODE) &&
81
+ + (previous->name != NULL) &&
82
+ + (sibling->name != NULL) &&
83
+ + (previous->name[0] == sibling->name[0]) &&
84
+ + (xmlStrEqual(previous->name, sibling->name)))
85
+ + {
86
+ + if ((sel->value2 == NULL) ||
87
+ + ((sibling->ns != NULL) &&
88
+ + (xmlStrEqual(sel->value2, sibling->ns->href))))
89
+ + indx++;
90
+ + }
91
+ + sibling = sibling->prev;
92
+ + }
93
+ + if (sibling == NULL) {
94
+ + /* hum going backward in document order ... */
95
+ + indx = 0;
96
+ + sibling = node;
97
+ + while (sibling != NULL) {
98
+ + if (sibling == previous)
99
+ + break;
100
+ + if ((sibling->type == XML_ELEMENT_NODE) &&
101
+ + (previous->name != NULL) &&
102
+ + (sibling->name != NULL) &&
103
+ + (previous->name[0] == sibling->name[0]) &&
104
+ + (xmlStrEqual(previous->name, sibling->name)))
105
+ + {
106
+ + if ((sel->value2 == NULL) ||
107
+ + ((sibling->ns != NULL) &&
108
+ + (xmlStrEqual(sel->value2,
109
+ + sibling->ns->href))))
110
+ + {
111
+ + indx--;
112
+ + }
113
+ + }
114
+ + sibling = sibling->next;
115
+ + }
116
+ + }
117
+ + if (sibling != NULL) {
118
+ + pos = XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival) + indx;
119
+ + /*
120
+ + * If the node is in a Value Tree we need to
121
+ + * save len, but cannot cache the node!
122
+ + * (bugs 153137 and 158840)
123
+ + */
124
+ + if (node->doc != NULL) {
125
+ + len = XSLT_RUNTIME_EXTRA(ctxt, sel->lenExtra, ival);
126
+ + if (!isRVT) {
127
+ + XSLT_RUNTIME_EXTRA(ctxt,
128
+ + sel->previousExtra, ptr) = node;
129
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival) = pos;
130
+ + }
131
+ + }
132
+ + } else
133
+ + pos = 0;
134
+ + } else {
135
+ + /*
136
+ + * recompute the index
137
+ + */
138
+ + xmlNodePtr parent = node->parent;
139
+ + xmlNodePtr siblings = NULL;
140
+ +
141
+ + if (parent) siblings = parent->children;
142
+ +
143
+ + while (siblings != NULL) {
144
+ + if (siblings->type == XML_ELEMENT_NODE) {
145
+ + if (siblings == node) {
146
+ + len++;
147
+ + pos = len;
148
+ + } else if ((node->name != NULL) &&
149
+ + (siblings->name != NULL) &&
150
+ + (node->name[0] == siblings->name[0]) &&
151
+ + (xmlStrEqual(node->name, siblings->name))) {
152
+ + if ((sel->value2 == NULL) ||
153
+ + ((siblings->ns != NULL) &&
154
+ + (xmlStrEqual(sel->value2, siblings->ns->href))))
155
+ + len++;
156
+ + }
157
+ + }
158
+ + siblings = siblings->next;
159
+ + }
160
+ + if ((parent == NULL) || (node->doc == NULL))
161
+ + nocache = 1;
162
+ + else {
163
+ + while (parent->parent != NULL)
164
+ + parent = parent->parent;
165
+ + if (((parent->type != XML_DOCUMENT_NODE) &&
166
+ + (parent->type != XML_HTML_DOCUMENT_NODE)) ||
167
+ + (parent != (xmlNodePtr) node->doc))
168
+ + nocache = 1;
169
+ + }
170
+ + }
171
+ + if (pos != 0) {
172
+ + ctxt->xpathCtxt->contextSize = len;
173
+ + ctxt->xpathCtxt->proximityPosition = pos;
174
+ + /*
175
+ + * If the node is in a Value Tree we cannot
176
+ + * cache it !
177
+ + */
178
+ + if ((!isRVT) && (node->doc != NULL) &&
179
+ + (nocache == 0)) {
180
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr) = node;
181
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival) = pos;
182
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->lenExtra, ival) = len;
183
+ + }
184
+ + }
185
+ + } else if ((sel != NULL) && (sel->op == XSLT_OP_ALL) &&
186
+ + (node->type == XML_ELEMENT_NODE)) {
187
+ + xmlNodePtr previous;
188
+ + int nocache = 0;
189
+ +
190
+ + previous = (xmlNodePtr)
191
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
192
+ + if ((previous != NULL) &&
193
+ + (previous->parent == node->parent)) {
194
+ + /*
195
+ + * just walk back to adjust the index
196
+ + */
197
+ + int indx = 0;
198
+ + xmlNodePtr sibling = node;
199
+ +
200
+ + while (sibling != NULL) {
201
+ + if (sibling == previous)
202
+ + break;
203
+ + if (sibling->type == XML_ELEMENT_NODE)
204
+ + indx++;
205
+ + sibling = sibling->prev;
206
+ + }
207
+ + if (sibling == NULL) {
208
+ + /* hum going backward in document order ... */
209
+ + indx = 0;
210
+ + sibling = node;
211
+ + while (sibling != NULL) {
212
+ + if (sibling == previous)
213
+ + break;
214
+ + if (sibling->type == XML_ELEMENT_NODE)
215
+ + indx--;
216
+ + sibling = sibling->next;
217
+ + }
218
+ + }
219
+ + if (sibling != NULL) {
220
+ + pos = XSLT_RUNTIME_EXTRA(ctxt,
221
+ + sel->indexExtra, ival) + indx;
222
+ + /*
223
+ + * If the node is in a Value Tree we cannot
224
+ + * cache it !
225
+ + */
226
+ + if ((node->doc != NULL) && !isRVT) {
227
+ + len = XSLT_RUNTIME_EXTRA(ctxt, sel->lenExtra, ival);
228
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr) = node;
229
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival) = pos;
230
+ + }
231
+ + } else
232
+ + pos = 0;
233
+ + } else {
234
+ + /*
235
+ + * recompute the index
236
+ + */
237
+ + xmlNodePtr parent = node->parent;
238
+ + xmlNodePtr siblings = NULL;
239
+ +
240
+ + if (parent) siblings = parent->children;
241
+ +
242
+ + while (siblings != NULL) {
243
+ + if (siblings->type == XML_ELEMENT_NODE) {
244
+ + len++;
245
+ + if (siblings == node) {
246
+ + pos = len;
247
+ + }
248
+ + }
249
+ + siblings = siblings->next;
250
+ + }
251
+ + if ((parent == NULL) || (node->doc == NULL))
252
+ + nocache = 1;
253
+ + else {
254
+ + while (parent->parent != NULL)
255
+ + parent = parent->parent;
256
+ + if (((parent->type != XML_DOCUMENT_NODE) &&
257
+ + (parent->type != XML_HTML_DOCUMENT_NODE)) ||
258
+ + (parent != (xmlNodePtr) node->doc))
259
+ + nocache = 1;
260
+ + }
261
+ + }
262
+ + if (pos != 0) {
263
+ + ctxt->xpathCtxt->contextSize = len;
264
+ + ctxt->xpathCtxt->proximityPosition = pos;
265
+ + /*
266
+ + * If the node is in a Value Tree we cannot
267
+ + * cache it !
268
+ + */
269
+ + if ((node->doc != NULL) && (nocache == 0) && !isRVT) {
270
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr) = node;
271
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival) = pos;
272
+ + XSLT_RUNTIME_EXTRA(ctxt, sel->lenExtra, ival) = len;
273
+ + }
274
+ + }
275
+ + }
276
+ +
277
+ + oldNode = ctxt->node;
278
+ + ctxt->node = node;
279
+ +
280
+ + match = xsltEvalXPathPredicate(ctxt, step->comp, comp->nsList, comp->nsNr);
281
+ +
282
+ + if (pos != 0) {
283
+ + ctxt->xpathCtxt->contextSize = oldCS;
284
+ + ctxt->xpathCtxt->proximityPosition = oldCP;
285
+ + }
286
+ + ctxt->node = oldNode;
287
+ +
288
+ + return match;
289
+ +}
290
+ +
291
+ +/**
292
+ * xsltTestCompMatch:
293
+ * @ctxt: a XSLT process context
294
+ * @comp: the precompiled pattern
295
+ @@ -854,12 +1126,6 @@ restart:
296
+ goto rollback;
297
+ break;
298
+ case XSLT_OP_PREDICATE: {
299
+ - xmlNodePtr oldNode;
300
+ - xmlDocPtr doc;
301
+ - int oldCS, oldCP;
302
+ - int pos = 0, len = 0;
303
+ - int isRVT;
304
+ -
305
+ /*
306
+ * when there is cascading XSLT_OP_PREDICATE, then use a
307
+ * direct computation approach. It's not done directly
308
+ @@ -875,274 +1141,10 @@ restart:
309
+ comp->nsList, comp->nsNr));
310
+ }
311
+
312
+ - doc = node->doc;
313
+ - if (XSLT_IS_RES_TREE_FRAG(doc))
314
+ - isRVT = 1;
315
+ - else
316
+ - isRVT = 0;
317
+ -
318
+ - /*
319
+ - * Depending on the last selection, one may need to
320
+ - * recompute contextSize and proximityPosition.
321
+ - */
322
+ - oldCS = ctxt->xpathCtxt->contextSize;
323
+ - oldCP = ctxt->xpathCtxt->proximityPosition;
324
+ - if ((sel != NULL) &&
325
+ - (sel->op == XSLT_OP_ELEM) &&
326
+ - (sel->value != NULL) &&
327
+ - (node->type == XML_ELEMENT_NODE) &&
328
+ - (node->parent != NULL)) {
329
+ - xmlNodePtr previous;
330
+ - int nocache = 0;
331
+ -
332
+ - previous = (xmlNodePtr)
333
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
334
+ - if ((previous != NULL) &&
335
+ - (previous->parent == node->parent)) {
336
+ - /*
337
+ - * just walk back to adjust the index
338
+ - */
339
+ - int indx = 0;
340
+ - xmlNodePtr sibling = node;
341
+ -
342
+ - while (sibling != NULL) {
343
+ - if (sibling == previous)
344
+ - break;
345
+ - if ((sibling->type == XML_ELEMENT_NODE) &&
346
+ - (previous->name != NULL) &&
347
+ - (sibling->name != NULL) &&
348
+ - (previous->name[0] == sibling->name[0]) &&
349
+ - (xmlStrEqual(previous->name, sibling->name)))
350
+ - {
351
+ - if ((sel->value2 == NULL) ||
352
+ - ((sibling->ns != NULL) &&
353
+ - (xmlStrEqual(sel->value2,
354
+ - sibling->ns->href))))
355
+ - indx++;
356
+ - }
357
+ - sibling = sibling->prev;
358
+ - }
359
+ - if (sibling == NULL) {
360
+ - /* hum going backward in document order ... */
361
+ - indx = 0;
362
+ - sibling = node;
363
+ - while (sibling != NULL) {
364
+ - if (sibling == previous)
365
+ - break;
366
+ - if ((sibling->type == XML_ELEMENT_NODE) &&
367
+ - (previous->name != NULL) &&
368
+ - (sibling->name != NULL) &&
369
+ - (previous->name[0] == sibling->name[0]) &&
370
+ - (xmlStrEqual(previous->name, sibling->name)))
371
+ - {
372
+ - if ((sel->value2 == NULL) ||
373
+ - ((sibling->ns != NULL) &&
374
+ - (xmlStrEqual(sel->value2,
375
+ - sibling->ns->href))))
376
+ - {
377
+ - indx--;
378
+ - }
379
+ - }
380
+ - sibling = sibling->next;
381
+ - }
382
+ - }
383
+ - if (sibling != NULL) {
384
+ - pos = XSLT_RUNTIME_EXTRA(ctxt,
385
+ - sel->indexExtra, ival) + indx;
386
+ - /*
387
+ - * If the node is in a Value Tree we need to
388
+ - * save len, but cannot cache the node!
389
+ - * (bugs 153137 and 158840)
390
+ - */
391
+ - if (node->doc != NULL) {
392
+ - len = XSLT_RUNTIME_EXTRA(ctxt,
393
+ - sel->lenExtra, ival);
394
+ - if (!isRVT) {
395
+ - XSLT_RUNTIME_EXTRA(ctxt,
396
+ - sel->previousExtra, ptr) = node;
397
+ - XSLT_RUNTIME_EXTRA(ctxt,
398
+ - sel->indexExtra, ival) = pos;
399
+ - }
400
+ - }
401
+ - } else
402
+ - pos = 0;
403
+ - } else {
404
+ - /*
405
+ - * recompute the index
406
+ - */
407
+ - xmlNodePtr parent = node->parent;
408
+ - xmlNodePtr siblings = NULL;
409
+ -
410
+ - if (parent) siblings = parent->children;
411
+ -
412
+ - while (siblings != NULL) {
413
+ - if (siblings->type == XML_ELEMENT_NODE) {
414
+ - if (siblings == node) {
415
+ - len++;
416
+ - pos = len;
417
+ - } else if ((node->name != NULL) &&
418
+ - (siblings->name != NULL) &&
419
+ - (node->name[0] == siblings->name[0]) &&
420
+ - (xmlStrEqual(node->name, siblings->name))) {
421
+ - if ((sel->value2 == NULL) ||
422
+ - ((siblings->ns != NULL) &&
423
+ - (xmlStrEqual(sel->value2,
424
+ - siblings->ns->href))))
425
+ - len++;
426
+ - }
427
+ - }
428
+ - siblings = siblings->next;
429
+ - }
430
+ - if ((parent == NULL) || (node->doc == NULL))
431
+ - nocache = 1;
432
+ - else {
433
+ - while (parent->parent != NULL)
434
+ - parent = parent->parent;
435
+ - if (((parent->type != XML_DOCUMENT_NODE) &&
436
+ - (parent->type != XML_HTML_DOCUMENT_NODE)) ||
437
+ - (parent != (xmlNodePtr) node->doc))
438
+ - nocache = 1;
439
+ - }
440
+ - }
441
+ - if (pos != 0) {
442
+ - ctxt->xpathCtxt->contextSize = len;
443
+ - ctxt->xpathCtxt->proximityPosition = pos;
444
+ - /*
445
+ - * If the node is in a Value Tree we cannot
446
+ - * cache it !
447
+ - */
448
+ - if ((!isRVT) && (node->doc != NULL) &&
449
+ - (nocache == 0)) {
450
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr) =
451
+ - node;
452
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival) =
453
+ - pos;
454
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->lenExtra, ival) =
455
+ - len;
456
+ - }
457
+ - }
458
+ - } else if ((sel != NULL) && (sel->op == XSLT_OP_ALL) &&
459
+ - (node->type == XML_ELEMENT_NODE)) {
460
+ - xmlNodePtr previous;
461
+ - int nocache = 0;
462
+ -
463
+ - previous = (xmlNodePtr)
464
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
465
+ - if ((previous != NULL) &&
466
+ - (previous->parent == node->parent)) {
467
+ - /*
468
+ - * just walk back to adjust the index
469
+ - */
470
+ - int indx = 0;
471
+ - xmlNodePtr sibling = node;
472
+ -
473
+ - while (sibling != NULL) {
474
+ - if (sibling == previous)
475
+ - break;
476
+ - if (sibling->type == XML_ELEMENT_NODE)
477
+ - indx++;
478
+ - sibling = sibling->prev;
479
+ - }
480
+ - if (sibling == NULL) {
481
+ - /* hum going backward in document order ... */
482
+ - indx = 0;
483
+ - sibling = node;
484
+ - while (sibling != NULL) {
485
+ - if (sibling == previous)
486
+ - break;
487
+ - if (sibling->type == XML_ELEMENT_NODE)
488
+ - indx--;
489
+ - sibling = sibling->next;
490
+ - }
491
+ - }
492
+ - if (sibling != NULL) {
493
+ - pos = XSLT_RUNTIME_EXTRA(ctxt,
494
+ - sel->indexExtra, ival) + indx;
495
+ - /*
496
+ - * If the node is in a Value Tree we cannot
497
+ - * cache it !
498
+ - */
499
+ - if ((node->doc != NULL) && !isRVT) {
500
+ - len = XSLT_RUNTIME_EXTRA(ctxt,
501
+ - sel->lenExtra, ival);
502
+ - XSLT_RUNTIME_EXTRA(ctxt,
503
+ - sel->previousExtra, ptr) = node;
504
+ - XSLT_RUNTIME_EXTRA(ctxt,
505
+ - sel->indexExtra, ival) = pos;
506
+ - }
507
+ - } else
508
+ - pos = 0;
509
+ - } else {
510
+ - /*
511
+ - * recompute the index
512
+ - */
513
+ - xmlNodePtr parent = node->parent;
514
+ - xmlNodePtr siblings = NULL;
515
+ -
516
+ - if (parent) siblings = parent->children;
517
+ -
518
+ - while (siblings != NULL) {
519
+ - if (siblings->type == XML_ELEMENT_NODE) {
520
+ - len++;
521
+ - if (siblings == node) {
522
+ - pos = len;
523
+ - }
524
+ - }
525
+ - siblings = siblings->next;
526
+ - }
527
+ - if ((parent == NULL) || (node->doc == NULL))
528
+ - nocache = 1;
529
+ - else {
530
+ - while (parent->parent != NULL)
531
+ - parent = parent->parent;
532
+ - if (((parent->type != XML_DOCUMENT_NODE) &&
533
+ - (parent->type != XML_HTML_DOCUMENT_NODE)) ||
534
+ - (parent != (xmlNodePtr) node->doc))
535
+ - nocache = 1;
536
+ - }
537
+ - }
538
+ - if (pos != 0) {
539
+ - ctxt->xpathCtxt->contextSize = len;
540
+ - ctxt->xpathCtxt->proximityPosition = pos;
541
+ - /*
542
+ - * If the node is in a Value Tree we cannot
543
+ - * cache it !
544
+ - */
545
+ - if ((node->doc != NULL) && (nocache == 0) && !isRVT) {
546
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr) =
547
+ - node;
548
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival) =
549
+ - pos;
550
+ - XSLT_RUNTIME_EXTRA(ctxt, sel->lenExtra, ival) =
551
+ - len;
552
+ - }
553
+ - }
554
+ - }
555
+ - oldNode = ctxt->node;
556
+ - ctxt->node = node;
557
+ -
558
+ - if (step->value == NULL)
559
+ - goto wrong_index;
560
+ - if (step->comp == NULL)
561
+ - goto wrong_index;
562
+ -
563
+ - if (!xsltEvalXPathPredicate(ctxt, step->comp, comp->nsList,
564
+ - comp->nsNr))
565
+ - goto wrong_index;
566
+ + if (!xsltTestPredicateMatch(ctxt, comp, node, step, sel))
567
+ + goto rollback;
568
+
569
+ - if (pos != 0) {
570
+ - ctxt->xpathCtxt->contextSize = oldCS;
571
+ - ctxt->xpathCtxt->proximityPosition = oldCP;
572
+ - }
573
+ - ctxt->node = oldNode;
574
+ break;
575
+ -wrong_index:
576
+ - if (pos != 0) {
577
+ - ctxt->xpathCtxt->contextSize = oldCS;
578
+ - ctxt->xpathCtxt->proximityPosition = oldCP;
579
+ - }
580
+ - ctxt->node = oldNode;
581
+ - goto rollback;
582
+ }
583
+ case XSLT_OP_PI:
584
+ if (node->type != XML_PI_NODE)
585
+ --
586
+ 1.8.4.1
587
+