-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-29289: Migrating ezxmltext with invalid name or id attributes #47
Conversation
'disable-id-value-check', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Disable the check for non-validating id/name values. This might increase execution time on large databases' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decrease? As in it might speeds up execution by skipping this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
/* | ||
// For debugging | ||
$records = $logHandler->getRecords(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For convenience, I would prefer it to remain there, and this is in a test so I thought it might be okay.
But I may also remove it if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we instead mock, that would cover the need for that afaik.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 besides the two nitpicks above
@@ -17,6 +17,8 @@ | |||
use eZ\Publish\API\Repository\LocationService; | |||
use eZ\Publish\API\Repository\Values\Content\ContentInfo; | |||
use eZ\Publish\API\Repository\Values\Content\Location; | |||
use Monolog\Handler\TestHandler; | |||
use Monolog\Logger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test/null logger available in PSR package to avoid relying on implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a null logger, but no test logger in PSR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you could mock LoggerInterface here as well right? or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added mock as suggested and testes that the log messages are actually correct.
It got a bit more complicated that you might suspected as the log message in some cases contained ids generated randomly by XSLT...
$this->expectedLogWarningWithWildcard[] = $line; | ||
$loggerStub->expects($this->at($logNo++)) | ||
->method('warning') | ||
->with($this->callback(array($this, 'validatelogWarningWithWildcard'))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what the * log lines do here, but might be relevant:
This could have been also the following to avoid using stageful $this->expectedLogWarningWithWildcard
property:
->with($this->callback(function($logMessage) use($expectedLogLines) {
$this->assert(...);
return true;
}));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, but might be improvement potential on the callback usage.
Fixed callback usage as suggested. Thanx |
/** | ||
* @var [] | ||
*/ | ||
private $expectedLogWarningWithWildcard = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can remove this now then ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
continue; | ||
} | ||
if (strpos($expectedLogLine, '*') !== false) { | ||
//$this->expectedLogWarningWithWildcard[] = $line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
This looks great now to me. |
$newValue = 'rewrite_' . $node->attributes->getNamedItem('id')->nodeValue; | ||
$newValue = preg_replace("/[^$whitelist]/", '_', $newValue); | ||
$node->attributes->getNamedItem('id')->nodeValue = $newValue; | ||
if ($this->logger !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this condition. That's why we using NullLogger
😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Previosly, the logger could actually be null, but that is not the case anymore.
Fixed.
@@ -163,6 +163,34 @@ protected function reportNonUniqueIds(DOMDocument $document, $contentFieldId) | |||
} | |||
} | |||
|
|||
protected function ValidateAttributeValues(DOMDocument $document, $contentFieldId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CS: Please use camelCase for method names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -320,7 +348,7 @@ protected function checkEmptyEmbedTags(DOMDocument $inputDocument) | |||
* @param null|int $contentFieldId | |||
* @return string | |||
*/ | |||
public function convert(DOMDocument $inputDocument, $checkDuplicateIds = false, $contentFieldId = null) | |||
public function convert(DOMDocument $inputDocument, $checkDuplicateIds = false, $checkIdValues = false, $contentFieldId = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Missing checkIdValues
parameter in docblock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!. Fixed
|
||
$whitelist = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-'; | ||
$replaceStr = ''; | ||
$nodes = $xpath->query("//*[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a comment explaining whats going on here 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe... explanation given...
@adam: All comments accommodated I believe.. Please have a look I'll rebase PR once you are done |
* #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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see this comment! 🙂
This PR fixes EZP-29289
It is not 100% bulletproof though;
It checks if first character in the attribute's value is white listed. It does not check the remaining characters. It would be possible to fix that, but it would require yet another XPath pass I believe.But I think this is good enought for now