0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-26 21:04:25 +08:00

538 Commits

Author SHA1 Message Date
Arseny Kapoulkine
6202519ca6 tests: Add memory safety tests for remove_children/attributes
The newly added tests make sure that during node/attribute destruction
we deallocate a few memory pages; this makes sure that we don't read
node data after it's being destroyed.

Also clean up formatting/style in the remove_* implementation a bit.
2019-09-17 20:34:40 -07:00
Tuan Anh Tran
fd7326fb91 feat: add remove_attributes() and remove_children() (#296)
These functions remove all attributes / child nodes in bulk which is faster than removing them one at a time.
2019-09-17 20:18:41 -07:00
Arseny Kapoulkine
c6607740a0 Never escape > in attribute values
According to XML spec, > sometimes needs to be escaped in PCDATA (when
it occurs as a ]]> pattern), but it doesn't need to be escaped in
attribute values.

Contributes to #272.
2019-09-11 21:35:03 -07:00
Arseny Kapoulkine
946de603b1 Don't escape attribute quotation symbol
When using double quotes for attributes, we don't need to escape '; when
using single quotes, we don't need to escape ".

This changes behavior to match 1.9 by default (where we don't escape ').

Contributes to #272.
2019-09-11 21:27:20 -07:00
Arseny Kapoulkine
44e4d7e40b Update version to 1.10
Note: this chang also updates PUGIXML_VERSION macro to allow for
double-digit minor versions; this preserves the continuity of versions
so PUGIXML_VERSION >= 190 will still work.
2019-09-11 21:09:50 -07:00
Joel Andres Granados
84e322738b Update nuget creation to VS2019 (#291)
Create visual studio projects that are vs2019 compliant.
* nuget_build.ps1 :
Introduce a new argument that will define how we implement the nuget
build. For now we accept 201{9,7.5.3} as possible argument values.

* pugixml_vs2019{,_static}.vcxproj :
Add two visual studio projects that build pugi with the latest SDK and
build tools

* appveyor.yml
- Add Visual Studio 2019 to build targets
- Add Visual Studio 201{9,3,5} to build_scripts. And call
  nuget_build.ps1 with a new argument.
- Add Visual Studio 2019 to the test_scripts.
2019-09-09 07:37:29 -07:00
Wolfgang Stöggl
fdf0295753 Fix minor typos (#286)
- Typos were found by codespell v1.15.0
2019-08-21 07:46:11 -07:00
Arseny Kapoulkine
a556845555 tests: Work around test warnings in clang-7
Self-assignment generates a Wself-assign-overloaded warning.
2019-08-21 07:45:27 -07:00
m-naumann
5a867cb1e3 Add support for using single quotes to enclose attribute values
This change adds format_attribute_single_quote flag that uses single quotes (`'`) instead of double quotes (`"`) for formatting attribute values.

Internal quotation marks are escaped using `"` and `'`.
2019-06-18 19:51:10 -07:00
denchat
86e0fe1980
Fix forgotten indentation 2019-06-10 00:35:17 +07:00
denchat
1312a46d91
std::random_shuffle is removed in current standard
use <random> 's generator and std::shuffle instead
2019-06-10 00:14:21 +07:00
Arseny Kapoulkine
8bf806c035 tests: Move control char tests to test_write.cpp
Also fix code style.
2019-03-09 06:58:07 -08:00
Yan Pas
138976fd95 unit test and doc 2019-03-08 19:17:19 +03:00
Arseny Kapoulkine
12e8b699ce tests: Expand out-of-memory union tests
We now have two tests: one tests behavior when we run out of space when
appending the node set (in which case the append fails), another one
tests behavior when we run out of space when filtering the node set (in
which case the set still contains redundant data).
2019-02-26 23:57:58 -08:00
Arseny Kapoulkine
c55ea3bc1e XPath: Make remove_duplicates generate stable order
Given an unsorted sequence, remove_duplicates would sort it using the
pointer value of attributes/nodes and then remove consecutive
duplicates.

This was problematic because it meant that the result of XPath queries
was dependent on the memory allocation pattern. While it's technically
incorrect to rely on the order, this results in easy to miss bugs.

This is particularly common when XPath queries use union operators -
although we also will call remove_duplicates in other cases.

This change reworks the code to use a hash set instead, using the same
hash function we use for compact storage. To make sure it performs well,
we allocate enough buckets for count * 1.5 (assuming all elements are
unique); since each bucket is a single pointer unlike xpath_node which
is two pointers, we need somewhere between size * 0.75 and size * 1.5
temporary storage.

The resulting filtering is stable - we remove elements that we have seen
before but we don't change the order - and is actually significantly
faster than sorting was.

With a large union operation, before this change it took ~56 ms per 100
query invocations to remove duplicates, and after this change it takes
~20ms.

Fixes #254.
2019-02-26 23:57:58 -08:00
Arseny Kapoulkine
930a701f1f tests: Disable flaky test
This test is very sensitive to the particular implementation of union
aggregation; for now lets disable this.

We need a more robust way to test union allocation failures.
2019-02-26 22:15:34 -08:00
Arseny Kapoulkine
7664bbf9af tests: Only use load_file_special_folder test on macOS
The behavior on Linux is very different between kernel versions, and it
triggers an unexpected OOM during sanitizer runs because somehow the
size is reported to be LONG_MAX. It's not clear that it helps us cover
any paths we don't cover otherwise - it would be nice to be able to test
failing to load a multi-gigabyte file on a 32-bit system, but we can't
do this easily atm anyway.
2018-11-27 08:07:31 -08:00
Arseny Kapoulkine
f9a2a7d19e Fix Wdouble-promotion warnings
We had a few places in test code and library source where we used an
implicit float->double cast; while it should preserve the value exactly,
gcc/clang implement this warning to make sure uses of double are intentional.

This change also adds the warning to Makefile to make sure we don't
regress on this warning.

Fixes #243.
2018-11-23 23:39:22 -08:00
Arseny Kapoulkine
aac75cd299 Escape TAB character in attribute values with &#09;
This change modifies the table entries for ctx_special_attr to treat TAB
character as special, which makes the output code escape it.

Before this change, trying to use TAB in an attribute value would output
it verbatim; during subsequent parsing, pugixml - and other compliant
parsers - would apply attribute-value normalization, turning the TAB
into a space and losing the original value.

Using &#09; fixes this; if an input document has &#09; in an attribute
value, that gets unescaped into \t during parsing and escaped back into
&#09; during output, which means we can now roundtrip values like this.

Fixes #242.
2018-11-19 22:26:21 -08:00
Arseny Kapoulkine
1a96777b11 tests: Fix XPath denorm tests on Intel compiler
Intel compiler by default sets flush-to-zero flags which causes our
denorm test to produce 0.0. So make sure that denorms work on FPU before
testing the string output.

Fixes #218.
2018-08-13 22:06:57 -07:00
Arseny Kapoulkine
6b9c07e6ed tests: Allow document_load_file_special_folder to load empty document
On some Debian systems it looks like we *can* open the current folder as
a file and read its contents, but parsing the result produces an empty
document. We now handle this case as well.

Fixes #225.
2018-07-30 07:32:09 -07:00
Arseny Kapoulkine
8436f2a69b tests: Fix PUGIXML_COMPACT build on some platforms
We need bad_alloc that lives in <new>, not <exception>.
2018-04-04 07:53:16 -07:00
Arseny Kapoulkine
474a4a3f73 tests: Fix PUGIXML_NO_XPATH,PUGIXML_COMPACT build
pugixml.hpp wasn't including the <exception> header in this build but
test code needed it.
2018-04-03 21:56:09 -07:00
Arseny Kapoulkine
5f4afe3bd2 tests: Fix PUGIXML_NO_XPATH build 2018-04-03 21:51:41 -07:00
Arseny Kapoulkine
62728d9c2e tests: Fix PUGIXML_NO_EXCEPTIONS tests 2018-04-02 21:51:04 -07:00
Arseny Kapoulkine
0c74e117b8 Update version to 1.9 2018-04-02 21:46:14 -07:00
Arseny Kapoulkine
a32585286a tests: Fix PUGIXML_NO_STL build 2018-04-02 21:33:03 -07:00
Arseny Kapoulkine
fe7b837868 tests: Fix PUGIXML_COMPACT+PUGIXML_WCHAR_MODE tests
Several tests got the buffer size wrong when sizeof(char_t)>1, and one
test didn't meet the carefully tuned allocation criteria under compact
mode due to the hash table usage and had to be changed a bit.
2018-03-16 21:33:26 -07:00
Arseny Kapoulkine
a55f575a03 tests: Fix OSX test failure
Apparently at some point OSX behavior when reading /dev/tty switched
from "can't open the file" to "the file can be opened and 0 bytes can be
read from it" which generates a wrong error and doesn't exercise the
code path we care about.
2017-12-22 11:30:15 -08:00
Arseny Kapoulkine
7c6d0010b3
Merge pull request #170 from zeux/move
This change implements move ctor and assign support for xml_document.

All node handles remain valid after the move and point to the new document; the only exception is the document node itself (that remains unmoved).

Move is O(document size) in theory because it needs to relocate immediate document children (there is just one in conformant documents) and all memory pages; in practice the memory pages only need the header adjusted, which is ~0.1% of the actual data size.

Move requires no allocations in general, except when using compact mode where some moves need to grow the hash table which can fail (throw).

Fixes #104
2017-11-13 13:24:43 -08:00
Arseny Kapoulkine
58611c8702 tests: Add compact move tests
This helps make sure our error handling logic works and is exercised.
2017-11-13 08:59:16 -08:00
Arseny Kapoulkine
492ebc22bc tests: Fix expansion-to-defined warning
This warning is new as of GCC 7 and highlights undefined behavior in the
preprocessor that ASAN detection was relying on.
2017-11-10 21:35:59 -08:00
Arseny Kapoulkine
0504fa4e90 tests: Add more tests for document move
These tests currently fail for compact mode because of ->reserve()
failing.
2017-10-26 08:36:05 -07:00
Arseny Kapoulkine
b0fc587a7f tests: Add more move tests
We now check that appending a child to a moved document performs no
allocations - this is already the case, but if we neglected to copy the
allocator state this test would fail.
2017-10-20 21:53:42 -07:00
Arseny Kapoulkine
50bc0d5a69 tests: Adjust move coverage tests
Large test wasn't testing shared parent condition properly - add one
more level of hierarchy so that it works as expected.
2017-09-25 22:54:42 -07:00
Arseny Kapoulkine
26ead385a7 tests: Add more move tests
Add a test that checks that static buffer pointer was moved correctly
by checking if offset_debug still works.
2017-09-25 22:52:26 -07:00
Arseny Kapoulkine
402b967fa9 tests: Add more move tests
Make sure we have coverage for empty documents and for large documents
that trigger compact_shared_parent != root for some pages.
2017-09-25 22:47:10 -07:00
Arseny Kapoulkine
faba4786c0 tests: Add more document move tests
Verify that move doesn't allocate and that it preserves structures
required for tree memory management and append_buffer in tact.
2017-09-25 22:38:30 -07:00
Arseny Kapoulkine
6eb7519dba tests: Add basic move tests
These just verify that move ctor/assignment operator work as expected in
simple cases - there are a number of ways in which the internal
structure can be incorrect...
2017-09-25 21:37:56 -07:00
Arseny Kapoulkine
f3e0f4249c tests: Add more stream coverage tests
These new tests test that tellg() can fail when being called the second
time, which leads to seekable implementation failing.
2017-06-23 08:44:52 -07:00
Arseny Kapoulkine
4564d31c76 tests: Add stream coverage tests
These tests simulate various error conditions when reading data from
streams - seeks failing in seekable streams, underflow throwing an
exception causing read to set badbit, etc.

This change also adjusts memory thresholds to cause a reliable out of
memory during construction of a final buffer for non-seekable streams.
2017-06-23 07:48:09 -07:00
Arseny Kapoulkine
20a8eced3b tests: Fix PUGIXML_WCHAR_MODE build 2017-06-22 22:18:16 -07:00
Arseny Kapoulkine
3870217381 tests: Add more XPath out of memory tests
This fixes missing coverage in translate_table_generate and
xpath_node_set_raw::append.
2017-06-22 22:11:43 -07:00
Arseny Kapoulkine
5867aff943 tests: Make using namespace more explicit
Hiding using namespace in common.hpp is somewhat surprising so remove
common.hpp and move using namespace into all .cpp files that need it.
2017-06-22 20:41:08 -07:00
Arseny Kapoulkine
4b371e10ee tests: Remove redundant pugi:: qualifier
Most tests have `using namespace pugi` which makes explicit
qualifications unnecessary.
2017-06-22 20:33:02 -07:00
Arseny Kapoulkine
2252927c04 Deprecate xml_document::load(const char*) and xml_node::select_single_node
These functions were deprecated via comments in 1.5 but never got the
deprecated attribute; now is the time!

Using deprecated functions produces a warning; to silence it, this
change moves the relevant tests to a separate translation unit that has
deprecation disabled.
2017-06-22 09:13:10 -07:00
Arseny Kapoulkine
9357837d2e Add VS2017 to AppVeyor test run
This requires moving the list of VS versions out of
autotest-appveyor.ps1 and into appveyor.yml.
2017-06-18 22:20:13 -07:00
Arseny Kapoulkine
0027b6ac79 tests: Improve XPath coverage
Add memory allocation failure test for concact with a very large list
and make sure we have every single axis covered with and without a
predicate, with and without a previous step.
2017-06-16 22:45:42 -07:00
Arseny Kapoulkine
08f102f14c tests: Add even more stream coverage tests
Apparently only narrow character streams had out of memory coverage -
fix that and also split this into a separate test.
2017-06-16 21:38:55 -07:00
Arseny Kapoulkine
86593c0999 tests: Add more stream coverage tests
Cover both char and wchar_t stream loading in a single run instead of
using pugi::char_t.
2017-06-16 17:08:00 -07:00