jenkins-bot has submitted this change and it was merged.

Change subject: Explicitly set a utf-8 charset in v2 text content-types
......................................................................


Explicitly set a utf-8 charset in v2 text content-types

All Parsoid content is consistently UTF-8 encoded. However, HTTP/1.1 standard
is still ISO-8859-1, so we need to make UTF-8 explicit for any text content we
emit.

Change-Id: I7bb51c62b97b8eb3026644757474311e9b531160
---
M api/routes.js
M lib/mediawiki.DOMPostProcessor.js
2 files changed, 13 insertions(+), 20 deletions(-)

Approvals:
  Cscott: Looks good to me, but someone else must approve
  GWicke: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/api/routes.js b/api/routes.js
index f2a06d3..b98c21c 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -322,19 +322,17 @@
                );
        }).timeout( REQ_TIMEOUT ).then(function() {
                apiUtils.setHeader(res, env, 'X-Parsoid-Performance', 
env.getPerformanceHeader());
-               var output = out.join('');
+               var output = out.join(''),
+                       contentType = 
'text/plain;profile=mediawiki.org/specs/wikitext/1.0.0;charset=utf-8';
                if ( v2 ) {
                        apiUtils.jsonResponse(res, env, {
                                wikitext: {
-                                       headers: {
-                                               // FIXME: get this from 
somewhere else
-                                               'content-type': 
'text/plain;profile=mediawiki.org/specs/wikitext/1.0.0'
-                                       },
+                                       headers: { 'content-type': contentType 
},
                                        body: output
                                }
                        });
                } else {
-                       apiUtils.setHeader(res, env, 'Content-Type', 
'text/x-mediawiki; charset=UTF-8');
+                       apiUtils.setHeader(res, env, 'content-type', 
contentType);
                        apiUtils.endResponse(res, env, output);
                }
 
@@ -381,30 +379,25 @@
 
        function sendRes(doc) {
                apiUtils.setHeader(res, env, 'X-Parsoid-Performance', 
env.getPerformanceHeader());
-               var output;
+               var output, contentType = 
'text/html;profile=mediawiki.org/specs/html/1.0.0;charset=utf-8';
                if ( v2 && v2.format === "pagebundle" ) {
-                       var dp = doc.getElementById('mw-data-parsoid');
-                       dp.parentNode.removeChild(dp);
+                       var dpScriptElt = doc.getElementById('mw-data-parsoid');
+                       dpScriptElt.parentNode.removeChild(dpScriptElt);
                        output = DU.serializeNode( res.local('body') ? doc.body 
: doc );
                        apiUtils.jsonResponse(res, env, {
                                // revid: 12345 (maybe?),
                                html: {
-                                       headers: {
-                                               // FIXME: get this from 
somewhere else
-                                               'content-type': 
'text/html;profile=mediawiki.org/specs/html/1.0.0'
-                                       },
+                                       headers: { 'content-type': contentType 
},
                                        body: output
                                },
                                "data-parsoid": {
-                                       headers: {
-                                               'content-type': 
'application/json;profile=mediawiki.org/specs/data-parsoid/0.0.1'
-                                       },
-                                       body: JSON.parse(dp.text)
+                                       headers: { 'content-type': 
dpScriptElt.getAttribute('type') },
+                                       body: JSON.parse( dpScriptElt.text )
                                }
                        });
                } else {
                        output = DU.serializeNode( res.local('body') ? doc.body 
: doc );
-                       apiUtils.setHeader(res, env, 'Content-Type', 
'text/html; charset=UTF-8');
+                       apiUtils.setHeader(res, env, 'content-type', 
contentType);
                        apiUtils.endResponse(res, env, output);
                }
 
@@ -547,7 +540,7 @@
                                        return resolve();
                                }
                                res.once( 'finish', resolve );
-                               apiUtils.setHeader( res, env, 'Content-Type', 
'text/plain; charset=UTF-8' );
+                               apiUtils.setHeader( res, env, 'content-type', 
'text/plain;charset=utf-8' );
                                apiUtils.sendResponse( res, env, 
logData.fullMsg(), logData.flatLogObject().code || 500 );
                        }).catch(function(e) {
                                console.error( e.stack || e );
diff --git a/lib/mediawiki.DOMPostProcessor.js 
b/lib/mediawiki.DOMPostProcessor.js
index 270f0ae..a352282 100644
--- a/lib/mediawiki.DOMPostProcessor.js
+++ b/lib/mediawiki.DOMPostProcessor.js
@@ -359,7 +359,7 @@
                var script = document.createElement("script");
                DU.addAttributes(script, {
                        id: "mw-data-parsoid",
-                       type: "application/json; 
spec=mediawiki.org/specs/parsoid/data/1.0"
+                       type: 
"application/json;profile=mediawiki.org/specs/data-parsoid/0.0.1;charset=utf-8"
                });
                script.appendChild( document.createTextNode(dp) );
                document.head.appendChild( script );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7bb51c62b97b8eb3026644757474311e9b531160
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: GWicke <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Marcoil <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to