Marcoil has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/82743


Change subject: Bug 53559: Fix problems with rt_testing results storing and 
entity escaping
......................................................................

Bug 53559: Fix problems with rt_testing results storing and entity escaping

There are two problems that contribute to the errors seen in Chrome for
some rt_testing page results:
- First, as reported on the bug, the client escapes all entities. As we're using
UTF-8 throughout, this is not necessary and takes up much more space than
needed.
- Second, TEXT fields in MySQL are capped at 64kb, which makes them too
small for some of the results. The result is clipped, producing the
bad-formed XML Chrome complains about.

To fix it, this patch adds code to only encode the strictly-necessary entities
and a SQL script to alter the results column to a MEDIUMTEXT field, which
should provide storage enough.

Bonus: Get the page's prefix correctly from the environment and remove
the total time timer from perfstats.

Change-Id: I23d02ee5c33fdf404a19ed00932d394f03040755
---
M js/tests/roundtrip-test.js
A js/tests/server/sql/alter_results_to_mediumtext.sql
M js/tests/server/sql/create_everything.mysql
3 files changed, 18 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/43/82743/1

diff --git a/js/tests/roundtrip-test.js b/js/tests/roundtrip-test.js
index 6fffc8f..6020d88 100755
--- a/js/tests/roundtrip-test.js
+++ b/js/tests/roundtrip-test.js
@@ -57,39 +57,47 @@
        return output;
 };
 
+var encodeXmlEntities = function( str ) {
+       return str.replace( /&/g, '&' )
+                         .replace( /</g, '&lt;' )
+                         .replace( />/g, '&gt;' )
+                         .replace( /"/g, '&quot;' )
+                         .replace( /'/g, '&apos;' );
+}
+
 var xmlCallback = function ( env, err, results ) {
        var i, result;
-       var prefix = ( env && env.wiki && env.wiki.iwp ) || '';
+       var prefix = ( env && env.conf && env.conf.wiki && env.conf.wiki.iwp ) 
|| '';
        var title = ( env && env.page && env.page.name ) || '';
 
-       var output = '<testsuite name="Roundtrip article ' + Util.encodeXml( 
prefix + ':' + title ) + '">';
+       var output = '<testsuite name="Roundtrip article ' + encodeXmlEntities( 
prefix + ':' + title ) + '">';
 
        if ( err ) {
                output += '<testcase name="entire article"><error 
type="parserFailedToFinish">';
-               output += Util.encodeXml( err.stack || err.toString() );
+               output += encodeXmlEntities( err.stack || err.toString() );
                output += '</error></testcase>';
        } else {
 
                for ( i = 0; i < results.length; i++ ) {
                        result = results[i];
 
-                       output += '<testcase name="' + Util.encodeXml( prefix + 
':' + title ) + ' character ' + result.offset[0].start + '">';
+                       output += '<testcase name="' + encodeXmlEntities( 
prefix + ':' + title ) + ' character ' + result.offset[0].start + '">';
 
                        if ( result.type === 'fail' ) {
                                output += '<failure 
type="significantHtmlDiff">\n';
 
                                output += '<diff class="wt">\n';
-                               output += Util.encodeXml( result.wtDiff );
+                               output += encodeXmlEntities( result.wtDiff );
                                output += '\n</diff>\n';
 
                                output += '<diff class="html">\n';
-                               output += Util.encodeXml( result.htmlDiff );
+                               output += encodeXmlEntities( result.htmlDiff );
                                output += '\n</diff>\n';
 
                                output += '</failure>\n';
                        } else {
                                output += '<skipped 
type="insignificantWikitextDiff">\n';
-                               output += Util.encodeXml( result.wtDiff );
+                               output += encodeXmlEntities( result.wtDiff );
                                output += '\n</skipped>\n';
                        }
 
@@ -407,6 +415,7 @@
                // Finish the total time now
                if ( env.profile && env.profile.time ) {
                        env.profile.time.total += new Date() - 
env.profile.time.total_timer;
+                       delete( env.profile.time.total_timer );
                }
                diff = jsDiff.diffLines( out, env.page.src );
                offsetPairs = Util.convertDiffToOffsetPairs( diff );
diff --git a/js/tests/server/sql/alter_results_to_mediumtext.sql 
b/js/tests/server/sql/alter_results_to_mediumtext.sql
new file mode 100644
index 0000000..74fc026
--- /dev/null
+++ b/js/tests/server/sql/alter_results_to_mediumtext.sql
@@ -0,0 +1 @@
+ALTER TABLE results CHANGE result result MEDIUMTEXT CHARACTER SET utf8 COLLATE 
utf8_bin NOT NULL;
diff --git a/js/tests/server/sql/create_everything.mysql 
b/js/tests/server/sql/create_everything.mysql
index 93e64b1..89d0645 100644
--- a/js/tests/server/sql/create_everything.mysql
+++ b/js/tests/server/sql/create_everything.mysql
@@ -25,7 +25,7 @@
        id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
        page_id INTEGER NOT NULL,
        commit_hash CHAR( 40 ) NOT NULL,
-       result TEXT NOT NULL
+       result MEDIUMTEXT NOT NULL
 ) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
 CREATE UNIQUE INDEX results_page_commit_idx ON results ( page_id, commit_hash 
);
 

-- 
To view, visit https://gerrit.wikimedia.org/r/82743
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I23d02ee5c33fdf404a19ed00932d394f03040755
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to