Fix migrate data error when params has excessively long strings

* The linter migrate code for linter_tag field and linter_template
   field are constrained by the database schema to 32 characters
   for the tag field and 255 characters for the template field.
   In some anomalous circumstances parsoid can report tag and or
   template fields in the linter_params object that exceed those
   character limits. This code truncates these excessively long
   strings to protect the database migrate update code from a
   length exceeded error.

Bug: T329113
Change-Id: I8af7c44759f172eae77d3519a6eac47110e9b1e7
This commit is contained in:
sbailey 2023-02-07 12:39:22 -08:00 committed by Jgiannelos
parent 07046457f0
commit 2768a70218
2 changed files with 28 additions and 0 deletions

View file

@ -604,7 +604,10 @@ class Database {
$templateInfo = $templateInfo->name ?? '';
}
}
$templateInfo = mb_strcut( $templateInfo, 0, self::MAX_TEMPLATE_LENGTH );
$tagInfo = $linter_params->name ?? '';
$tagInfo = mb_strcut( $tagInfo, 0, self::MAX_TAG_LENGTH );
// compare the content of linter_params to the template and tag field contents
// and if they diverge, update the field with the correct template and tag info.

View file

@ -356,6 +356,20 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
'TestPageTagAndTemplateMultipart',
$error );
// Create special case test for params containing tag and template info strings exceeding the fields lengths
$tagWithMoreThan30Characters = "center tag exceeding 30 characters";
$templateWithMoreThan250Characters = str_repeat( "Template:Echo longer than 250 characters ", 8 );
$error = [
'type' => 'obsolete-tag',
'location' => [ 0, 10 ],
'params' => [ "name" => $tagWithMoreThan30Characters,
"templateInfo" => $templateWithMoreThan250Characters ],
'dbid' => null,
];
$titleAndPageLengthExceeded = $this->createTitleAndPageForTagsAndRunJob(
'TestPageTagAndTemplateLengthExceeded',
$error );
// Verify the create page function did not populate the linter_tag and linter_template field for TestPage0
$pageId = $titleAndPages[ 0 ][ 'pageID' ];
$tag = $this->getTagForPage( $pageId );
@ -380,6 +394,17 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
$this->assertEquals( "center", $tag );
$template = $this->getTemplateForPage( $titleAndPageMultipart[ 'pageID' ] );
$this->assertEquals( "multi-part-template-block", $template );
// Verify special case test for migrate code encountering params with tag and template string length exceeded
$tagTruncated = "center tag exceeding 30 charac";
$templateTruncated = "Template:Echo longer than 250 characters Template:Echo longer than 250 characters " .
"Template:Echo longer than 250 characters Template:Echo longer than 250 characters " .
"Template:Echo longer than 250 characters Template:Echo longer than 250 characters Temp";
$tag = $this->getTagForPage( $titleAndPageLengthExceeded[ 'pageID' ] );
$this->assertEquals( $tagTruncated, $tag );
$template = $this->getTemplateForPage( $titleAndPageLengthExceeded[ 'pageID' ] );
$this->assertEquals( $templateTruncated, $template );
}
public function testDropInlineMediaCaptionLints() {