Skip to content

Commit

Permalink
fixup! EZP-29289: Migrating ezxmltext with invalid name or id attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl committed Jun 21, 2018
1 parent 52d2f68 commit 3650835
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/FieldType/XmlText/Converter/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ protected function validateAttributeValues(DOMDocument $document, $contentFieldI

$whitelist = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-';
$replaceStr = '';
/*
* We want to pick elements which has id value
* #1 not starting with a..z or '_'
* #2 not a..z, '0..9', '_' or '-' after 1st character
* So, no xpath v2 to our disposal...
* 1st line : we check the 1st char(substring) in id, converts it to 'a' if it in whitelist(translate), then check if it string now starts with 'a'(starts-with), then we invert result(not)
* : So we replace first char with 'a' if it is whitelisted, then we select the element if id value does not start with 'a'
* 2nd line: now we check remaining(omit 1st char) part of string (substring), removes any character that *is* whitelisted(translate), then check if there are any non-whitelisted characters left(string-lenght)
* 3rd line: Due to the not() in 1st line, we pick all elements not matching that 1st line. That also includes elements not having a xml:id at all..
* : So, we want to make sure we only pick elements which has a xml:id attribute.
*/
$nodes = $xpath->query("//*[
(
not(starts-with(translate(substring(@xml:id, 1, 1), '$whitelist1st', '$replaceStr1st'), 'a'))
Expand Down

0 comments on commit 3650835

Please sign in to comment.