Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ QueryPath Changelog
- Consolidate the sibling and ancestor walks behind `next()`, `prev()`, `nextAll()`, `prevAll()`, `nextUntil()`, `prevUntil()`, `parent()`, `parents()`, `parentsUntil()` and `closest()` into one helper, so a fix to one no longer has to be repeated in its mirror (issue #115). As a side effect, `parentsUntil()` no longer loops forever on an element that is not attached to the document, and `nextUntil('')` and `prevUntil('')` treat an empty selector as no selector, as the other methods already did, instead of throwing `QueryPath\CSS\ParseException`. `closest('')` returns an empty set, as in jQuery. `nextUntil()`, `prevUntil()` and `parentsUntil()` also stop at an element already collected from an earlier starting element, as `nextAll()` and `prevAll()` do, so `nextUntil()` on each of 2000 siblings falls from about 100 ms to 1 ms
- **Behaviour change.** `prevAll()`, `prevUntil()`, `nextAll()`, `nextUntil()`, `siblings()`, `parent()` and `closest()` now return the results for a multi-element set in jQuery's order, instead of grouped by starting element (issue #117). `prevAll()` and `prevUntil()` return reverse document order, as `parents()` and `parentsUntil()` already did, and the others return document order. `qp($xml, 'c')->add('d')->prevAll()` now returns `c, b, a` rather than `b, a, c`. `next()` and `prev()` keep the order of the starting elements, as in jQuery, and the results for a single starting element are unchanged
- **Behaviour change.** A positional pseudo-class (`:first`, `:eq()`, `:last`, ...) in the stop selector of `nextUntil()`, `prevUntil()` and `parentsUntil()` now counts across the whole document, as jQuery's does, instead of seeing each sibling or ancestor as a one-element set (issue #118). `nextUntil(':first')` used to stop at once and now walks to the end, and `nextUntil(':eq(3)')` stops at the fourth element in the document. `closest()` no longer matches a positional selector at all, as in jQuery, where `closest(':first')` used to return the element itself. `next()`, `prev()` and `parent()` still test each candidate on its own, which agrees with jQuery for a single starting element
- Fix `dataURL($attr)` returning `NULL` for a data URL whose MIME type contains punctuation, including the `application/octet-stream` default that `dataURL($attr, $data)` writes, so the getter could not read back what the setter wrote. Types such as `image/svg+xml` are now read too

# 4.3.0

Expand Down
3 changes: 2 additions & 1 deletion src/DOMQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ public function dataURL($attr, $data = null, $mime = 'application/octet-stream',
}

// So 1 and 2 should be MIME types, and 3 should be the base64-encoded data.
$regex = '/^data:([a-zA-Z0-9]+)\/([a-zA-Z0-9]+);base64,(.*)$/';
// The type and subtype accept the characters RFC 6838 allows, such as the "-" in application/octet-stream.
$regex = '/^data:([a-zA-Z0-9!#$&^_.+-]+)\/([a-zA-Z0-9!#$&^_.+-]+);base64,(.*)$/';
$matches = [];
preg_match($regex, $data, $matches);

Expand Down
16 changes: 16 additions & 0 deletions tests/QueryPath/DOMQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,22 @@ public function testDataURL()
$this->assertEquals('text/plain', $result['mime'], 'Should return the original MIME');
}

public function testDataURLRoundTripsMimeTypesWithPunctuation()
{
$xml = '<?xml version="1.0"?><root><item/></root>';
$qp = qp($xml, 'item');

// The default MIME type, written when none is given.
$qp->dataURL('secret', 'Hi!');
$this->assertSame(['mime' => 'application/octet-stream', 'data' => 'Hi!'], $qp->dataURL('secret'));

$qp->dataURL('secret', '<svg/>', 'image/svg+xml');
$this->assertSame(['mime' => 'image/svg+xml', 'data' => '<svg/>'], $qp->dataURL('secret'));

$qp->dataURL('secret', '{}', 'application/vnd.api+json');
$this->assertSame(['mime' => 'application/vnd.api+json', 'data' => '{}'], $qp->dataURL('secret'));
}

public function testEncodeDataURL()
{
$data = QueryPath::encodeDataURL('Hi!', 'text/plain');
Expand Down