1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-29 21:46:59 +03:00

485 Commits

Author SHA1 Message Date
Nick Wellnhofer
f39fd66ea7 Fix namespace::node() XPath expression
Make sure that xmlXPathNodeSetAddNs is called for namespace nodes when
matched with a namespace::node() step. This correctly sets the parent
of namespace nodes. Note that xmlXPathNodeSetAddNs must only be called
if working on the namespace axis. Otherwise, the context node is not
the parent of the namespace node and the standard XP_TEST_HIT macro
must be invoked. This explains the errors in the C14N tests that the
old TODO comment mentioned.
2016-04-27 11:21:35 +02:00
Nick Wellnhofer
e289390362 Fix parsing of NCNames in XPath
The NCName parser would allow any NameChar as start character. For
example, the following XPath expressions would compile:

    self::-abc
    self::0abc
    self::.abc
2016-04-23 19:12:47 +02:00
Jan Pokorný
bb654feb9a Fix typos: dictio{ nn -> n }ar{y,ies}
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2016-04-15 22:22:48 +08:00
Shlomi Fish
d5bd2a9a40 Correct a typo. 2016-04-11 09:42:23 +08:00
Nick Wellnhofer
3eaedba1b6 Fix previous change to node sort order
Commit ba58f23 broke comparison of nodes from different documents.
Thanks to Olli Pottonen for the report.
2015-07-11 14:27:34 +02:00
Nick Wellnhofer
ba58f23c60 Fix order of root nodes
Make sure root nodes are sorted before other nodes.
2015-03-08 16:44:11 +01:00
Nick Wellnhofer
f6aaabce85 Allow attributes on descendant-or-self axis
If the context node is an attribute, the attribute itself is on the
descendant-or-self axis. The principal node type of this axis is element,
so the only node test that can return the attribute is "node()". In other
words, "@attr/descendant-or-self::node()" is equivalent to "@attr".

This matches the behavior of Saxon-CE.
2015-03-08 16:25:52 +01:00
Nick Wellnhofer
07def30fa7 Restore context size and position after XPATH_OP_ARG
Fixes a bug with predicates:
https://mail.gnome.org/archives/xml/2014-March/msg00014.html
2014-03-24 13:02:06 +01:00
Jan Pokorný
75801652a2 Fix typos in {tree,xpath}.c (errror)
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2014-02-06 10:47:47 +01:00
Nick Wellnhofer
03c6723043 Handling of XPath function arguments in error case
The XPath engine tries to guarantee that every XPath function can pop
'nargs' non-NULL values off the stack. libxslt, for example, relies on
this assumption. But the check isn't thorough enough if there are errors
during the evaluation of arguments. This can lead to segfaults:

https://mail.gnome.org/archives/xslt/2013-December/msg00005.html

This commit makes the handling of function arguments more robust.

* Bail out early when evaluation of XPath function arguments fails.
* Make sure that there are 'nargs' arguments in the current call frame.
2013-12-20 17:45:04 +01:00
Gaurav
fcd4583189 Fix XPath node comparison bug
For https://bugzilla.gnome.org/show_bug.cgi?id=715143
2013-11-28 23:01:44 +08:00
Nick Wellnhofer
e8de99f90c Fix XPath expressions of the form '@ns:*'
Use namespace for match-all queries on the attribute axis.
2013-08-05 01:26:25 +02:00
Nick Wellnhofer
b4bcba23f6 Fix XPath '//' optimization with predicates
My attempt to optimize XPath expressions containing '//' caused a
regression reported in bug #695699. This commit disables the
optimization for expressions of the form '//foo[predicate]'.
2013-08-05 00:15:11 +02:00
Denis Pauk
e28c8a1ace #705267 - add additional defines checks for support "./configure --with-minimum"
https://bugzilla.gnome.org/show_bug.cgi?id=705267
2013-08-03 22:00:17 +08:00
Daniel Veillard
b9e4d5b639 Remove occasional leading space in XPath number formatting
https://bugzilla.gnome.org/show_bug.cgi?id=704528

Somehow snprintf "%*.*e" can generate a leading space, remove it
2013-07-22 13:21:31 +08:00
Alex Bligh
28876afb4e Add xmlXPathSetContextNode and xmlXPathNodeEval
This patch adds xmlXPathSetContextNode and xmlXPathNodeEval,
which make it easier to evaluation XPath expressions with a
context node other than the document root without poking about
inside the internals of the context.

This patch is compile-tested only, and is my first libxml2
contribution, so please go easy.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
2013-04-01 16:42:12 +08:00
Daniel Veillard
713434d230 Silence a clang warning
as reported by Hans Wennborg <hans@chromium.org>
2012-09-26 10:21:06 +08:00
Daniel Veillard
7651606f31 Various cleanups to avoid compiler warnings 2012-09-11 14:02:08 +08:00
Daniel Veillard
f8e3db0445 Big space and tab cleanup
Remove all space before tabs and space and tabs at end of lines.
2012-09-11 13:26:36 +08:00
Daniel Veillard
47881284ae Add a forbidden variable error number and message to XPath
Related to https://bugzilla.gnome.org/show_bug.cgi?id=680938

When the XML_XPATH_NOVAR flags is being used it means that
variables are forbidden, not that they are missing
2012-09-07 14:24:50 +08:00
Daniel Veillard
1bd45d1309 Change the XPath code to percolate allocation errors
looping 1000 time on an error stating that a nodeset has
grown out of control is useless, make sure we percolate
error up to the various loops and break when errors occurs
2012-09-05 15:35:19 +08:00
Daniel Veillard
510e7583f4 Fix a Timsort function helper comment 2012-09-04 11:50:36 +08:00
Vojtech Fried
3e031b7dae Switching XPath node sorting to Timsort
I use libxml xpath engine on quite large (and mostly "flat") xml files.
It seems that Shellsort, that is used in xmlXPathNodeSetSort is a
performance bottleneck for my case. I have read some posts about sorting
in libxml in the libxml archive, but I agree that qsort was not the way
to go. I experimented with Timsort instead and my results were good for
me. For about 10000 nodes, my test was about 5x faster with Timsort,
for 1000 nodes about 10% faster, for small data files, the difference
was not measurable.
* timsort.h: the algorithm, kept in a separate header
* xpath.c: plug in the new algorithm in xmlXPathNodeSetSort
* Makefile.am: add the header to the EXTRA_DIST
* doc/apibuild.py: avoid indexing the new header
2012-08-24 16:52:44 +08:00
Nick Wellnhofer
622705398a Optimizing '//' in XPath expressions
When investigating the libxslt performance problem reported in bug
#657665, I found that '//' in XPath expressions can be very slow when
working on large subtrees.

One of the reasons is the seemingly quadratic time complexity of the
duplicate checks when merging result nodes. The other is a missed
optimization for expressions of the form
'descendant-or-self::node()/axis::test'. Since '//' is expanded to
'/descendant-or-self::node()/', this type of expression is quite common.
Depending on the axis of the expression following the
'descendant-or-self' step, the following replacements can be made:

from descendant-or-self::node()/child::test
to   descendant::test

from descendant-or-self::node()/descendant::test
to   descendant::test

from descendant-or-self::node()/self::test
to   descendant-or-self::test

from descendant-or-self::node()/descendant-or-self::test
to   descendant-or-self::test

'test' can be any kind of node test.

With these replacements the possibly huge result of
'descendant-or-self::node()' doesn't have to be stored temporarily, but
can be processsed in one pass. If the resulting nodeset is small, the
duplicate checks aren't a problem.

I found that there already is a function called
xmlXPathRewriteDOSExpression which performs this optimization for a very
limited set of cases. It employs a complicated iteration scheme for
rewritten expressions. AFAICS, this can be avoided by simply changing
the axis of the expression like described above.

With the attached patch against libxml2 and the files from bug #657665 I
got the following results.

Before:

$ time xsltproc/xsltproc --noout service-names-port-numbers.xsl
service-names-port-numbers.xml
real    2m56.213s
user    2m56.123s
sys     0m0.080s

After:

$ time xsltproc/xsltproc --noout service-names-port-numbers.xsl
service-names-port-numbers.xml
real    0m3.836s
user    0m3.764s
sys     0m0.060s

I also ran the libxml2 and libxslt test suites with the patch and
couldn't detect any breakage.

Nick

>From e0f5a8261760e4f257b90410be27657e984237c8 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Sun, 19 Aug 2012 18:20:22 +0200
Subject: [PATCH] Optimizations for descendant-or-self::node()

Currently, the function xmlXPathRewriteDOSExpression optimizes expressions
of type '//child'. Instead of adding a 'rewriteType' and doing a compound
traversal, the same can be achieved simply by setting the axis of the node
test from 'child' to 'descendant'.

There are also many other cases that can be optimized similarly. This
commit augments xmlXPathRewriteDOSExpression to essentially rewrite the
following subexpressions:

- descendant-or-self::node()/child:: to descendant::
- descendant-or-self::node()/descendant:: to descendant::
- descendant-or-self::node()/self:: to descendant-or-self::
- descendant-or-self::node()/descendant-or-self:: to descendant-or-self::

Since the '//' shortcut in XPath is translated to
'/descendant-or-self::node()/', this greatly speeds up expressions using
'//' on large subtrees.
2012-08-24 12:04:25 +08:00
Daniel Veillard
3e62adbe39 Adding various checks on node type though the API
Specifially checking against namespace nodes before accessing node
pointers
2012-08-09 14:24:02 +08:00
Daniel Veillard
cd852ad154 Implement some default limits in the XPath module
This adds some internal limitationson XPath expression complexity,
and limits at runtime like depth of the stack and maximum size
for nodeset.
* xpath.c: implement the above as well as the maximum Name lenght
2012-07-30 10:12:18 +08:00
Daniel Veillard
ade10f2c57 Convert XPath to xmlBuf
Easy as no buffer was exported in the APIs
2012-07-23 14:24:26 +08:00
Daniel Veillard
1d4526f6f4 Fix missing error status in XPath evaluation
Started by Chris Evans, I added a few more place where the
error should have been set in the evaluation context.
2011-10-11 16:34:34 +08:00
Daniel Veillard
f5048b3e71 Hardening of XPath evaluation
Add a mechanism of frame for XPath evaluation when entering a function
or a scoped evaluation, also fix a potential problem in predicate
evaluation.
2011-08-19 11:07:51 +08:00
Stefan Kost
a15404034c xpath: remove unused variable
As noted by gcc, this variable is not beeing used.
2011-05-09 11:48:21 +03:00
Chris Evans
d7958b21e7 Fix some potential problems on reallocation failures
The count was incremented before the allocation
and not fixed in case of failure
* xpath.c: corrects a few instances where the available count of some
           structure is updated before we know the allocation actually
           succeeds
2011-03-23 08:13:06 +08:00
Daniel Veillard
fec31bcd45 Small fix for previous commit 2010-11-18 11:07:24 +01:00
Daniel Veillard
df83c17e5a Fix a potential freeing error in XPath 2010-11-17 14:12:14 +01:00
Daniel Veillard
0cbeb50ee0 Fix a potential memory access error
in case of a previus allocation error
2010-11-15 12:10:14 +01:00
Phil Shafer
ee32ad3c0f 629325 XPath rounding errors first cleanup
https://bugzilla.gnome.org/show_bug.cgi?id=629325
not a full solution as Vincent Lefevre pointed out but
an incremental improvement over the status-quo
2010-11-03 20:53:55 +01:00
Daniel Veillard
ea90b89414 Fix a change of semantic on XPath preceding and following axis
This was introduced in the prevous fix, while preceding-sibling and
following sibling axis are empty for attributes and namespaces,
preceding and following axis should still work based on the parent
element. However the parent element is not available for a namespace
node, so we keep the axis empty in that case.
2010-10-22 15:50:50 +02:00
Daniel Veillard
2f3523f61f Fix a leak in XPath compilation
Sometimes a not well formed XPath expression could lead to a
leak as reported by Ralf Junker <ralfjunker@gmx.de>
2010-10-15 18:30:29 +02:00
Daniel Veillard
91d19754d4 Fix the semantic of XPath axis for namespace/attribute context nodes
The processing of namespace and attributes nodes was not compliant
to the XPath-1.0 specification
2010-10-15 14:30:52 +02:00
Marius Wachtler
2ddecc2386 Fix a small bug in XPath evaluation code 2010-10-12 09:09:07 +02:00
Martin
729601f157 Fix memory leak in xmlXPathEvalExpression()
* xpath.c: plug some leaks when parsing misformed XPath expressions
* python/tests/xpathleak.py: expand the regression tests for those
2009-10-12 22:42:26 +02:00
Daniel Veillard
594e5dfb48 Chasing dead assignments reported by clang-scan
* SAX2.c dict.c error.c hash.c nanohttp.c parser.c python/libxml.c
  relaxng.c runtest.c tree.c valid.c xinclude.c xmlregexp.c xmlsave.c
  xmlschemas.c xpath.c xpointer.c: mostly removing unneded affectations,
  but this led to a few real bugs and some part not yet understood
  (relaxng/interleave)
2009-09-07 14:58:47 +02:00
Daniel Veillard
13cee4e37b Fix a bunch of scan 'dead increments' and cleanup
* HTMLparser.c c14n.c debugXML.c entities.c nanohttp.c parser.c
  testC14N.c uri.c xmlcatalog.c xmllint.c xmlregexp.c xpath.c:
  fix unused variables, or unneeded increments as well as a couple
  of space issues
* runtest.c: check for NULL before calling unlink()
2009-09-05 14:52:55 +02:00
Daniel Veillard
bccae2d210 * c14n.c debugXML.c doc/examples/io2.c parser.c schematron.c
valid.c xmlschemas.c xmlwriter.c xpath.c: use %s to printf string
  patch by Christian Persch, fixes #581612
2009-06-04 11:22:45 +02:00
Daniel Veillard
48b3eb22c2 fixes for Borland/CodeGear/Embarcadero compilers by Eric Zurcher Daniel
* include/wsockcompat.h win32/Makefile.bcb xpath.c: fixes for
  Borland/CodeGear/Embarcadero compilers by Eric Zurcher
Daniel

svn path=/trunk/; revision=3822
2009-03-25 09:51:19 +00:00
Daniel Veillard
db3ce96906 xmlXPathRegisterNs should not allow enpty prefixes daniel
* xpath.c: xmlXPathRegisterNs should not allow enpty prefixes
daniel

svn path=/trunk/; revision=3821
2009-03-25 09:43:49 +00:00
Daniel Veillard
f63085de5e port patch from Marcus Meissner to add gcc checking for printf like
* include/libxml/parser.h include/libxml/xmlwriter.h
  include/libxml/relaxng.h include/libxml/xmlversion.h.in
  include/libxml/xmlwin32version.h.in include/libxml/valid.h
  include/libxml/xmlschemas.h include/libxml/xmlerror.h:
  port patch from Marcus Meissner to add gcc checking for
  printf like functions parameters, should fix #65068
* doc/apibuild.py doc/*: modified the script accordingly
  and regenerated
* xpath.c xmlmemory.c threads.c: fix a few warnings
Daniel

svn path=/trunk/; revision=3813
2009-01-18 20:53:59 +00:00
Daniel Veillard
074f37e7eb applied a couple of patches from Martin avoiding some leaks, fixinq QName
* schematron.c xpath.c: applied a couple of patches from Martin
  avoiding some leaks, fixinq QName checks in XPath, XPath debugging
  and schematron code cleanups.
* python/tests/Makefile.am python/tests/xpathleak.py: add the
  specific regression tests, just tweak it to avoid output by default
Daniel

svn path=/trunk/; revision=3791
2008-09-01 13:38:22 +00:00
Daniel Veillard
45490aebe7 space and tabs cleanup Daniel
* xpath.c: space and tabs cleanup
Daniel

svn path=/trunk/; revision=3756
2008-07-29 09:13:19 +00:00
Daniel Veillard
f88d849a4e two patches from Alvaro Herrera to avoid problem when running out of
* xpath.c: two patches from Alvaro Herrera to avoid problem when
  running out of memory in XPath evaluations.
Daniel

svn path=/trunk/; revision=3721
2008-04-01 08:00:31 +00:00
William M. Brack
f179456d0f fixed mlXPathCompOpEvalPositionalPredicate problem with object caching
* xpath.c: fixed mlXPathCompOpEvalPositionalPredicate problem
  with object caching (bug #469410)

svn path=/trunk/; revision=3653
2007-08-23 12:58:13 +00:00