Subramanya Sastry has uploaded a new change for review.

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


Change subject: (Bug 48941) Try #2: Normalize ext. attributes in 
ExtensionHandler
......................................................................

(Bug 48941) Try #2: Normalize ext. attributes in ExtensionHandler

* Commit 2001f875 attempted to normalize extension attributes in
  the tokenizer.  However, this turned out to buggy since templated
  attribute values may not be fully expanded strings yet.

  en:Richter's_scale crashed.

* Moved the normalization code to extension handler, and only on
  native extension attributes (since PHP preprocessor will deal with
  the cases it handles).

* This fix still cannot handle template attribute values for extensions
  since they are not fully expanded yet at the time the native handler
  is invoked.  See FIXME in ext.core.ExtensionHandler alongwith an idea
  of how we might be able to deal with this.

  So, <ref name='  {{echo| foo}} ' /> will not normalize to
  <ref name='foo' /> at this time.  We can special case the fix for
  ref and references in ext.Cite.js, but if we can find a generic
  solution, that would be btter.

* en:Richter's_scale no longer crashes now.

Change-Id: I7e96fb6d2af444ac2561999de4b01a98a4f29275
---
M js/lib/ext.core.ExtensionHandler.js
M js/lib/mediawiki.Util.js
M js/lib/pegTokenizer.pegjs.txt
3 files changed, 36 insertions(+), 11 deletions(-)


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

diff --git a/js/lib/ext.core.ExtensionHandler.js 
b/js/lib/ext.core.ExtensionHandler.js
index 84a2881..da95124 100644
--- a/js/lib/ext.core.ExtensionHandler.js
+++ b/js/lib/ext.core.ExtensionHandler.js
@@ -94,6 +94,21 @@
 };
 
 ExtensionHandler.prototype.onExtension = function ( token, frame, cb ) {
+       function normalizeExtOptions(options) {
+               // Normalize whitespace in extension attribute values
+               // Mimics Sanitizer::decodeTagAttributes from the PHP parser
+               //
+               // Expects all values to have been fully expanded to string
+               for (var i = 0, n = options.length; i < n; i++) {
+                       var o = options[i];
+                       // SSS FIXME: This wont normalize options in all cases.
+                       if (o.v.constructor === String) {
+                               o.v = o.v.trim().replace(/(\s+)/g, ' ');
+                       }
+               }
+               return options;
+       }
+
        var extensionName = token.getAttribute('name'),
            nativeHandler = this.nativeExtHandlers[extensionName],
                // TODO: use something order/quoting etc independent instead of 
src
@@ -101,6 +116,26 @@
                cachedExpansion = this.manager.env.extensionCache[cacheKey];
        if ( nativeHandler ) {
                // No caching for native extensions for now.
+               token = token.clone();
+               token.setAttribute('options', 
normalizeExtOptions(token.getAttribute('options')));
+
+               // SSS FIXME: We seem to have a problem on our hands here.
+               //
+               // AttributeExpander runs after ExtensionHandler which means
+               // the native handlers will not receive fully expanded tokens.
+               //
+               // In the case of Cite.ref and Cite.references, this is not an 
issue
+               // since the final processing takes place in the DOM PP phase,
+               // by which time the marker tokens would have had everything 
expanded.
+               // But, this may not be true for other exensions.
+               //
+               // So, we wont be able to robustly support templated ext. 
attributes
+               // without a fix for this since attribute values might be 
ext-generated
+               // and ext-attribute values might be templated.
+               //
+               // The fix might require breaking this cycle by 
expliclitly-expanding
+               // ext-attribute-values here in a new pipeline.  TO BE DONE.
+
                nativeHandler(token, cb);
        } else if ( cachedExpansion ) {
                //console.log('cache hit for', 
JSON.stringify(cacheKey.substr(0, 50)));
diff --git a/js/lib/mediawiki.Util.js b/js/lib/mediawiki.Util.js
index 77237b3..9b2f2f4 100644
--- a/js/lib/mediawiki.Util.js
+++ b/js/lib/mediawiki.Util.js
@@ -901,16 +901,6 @@
                        (cp >= 0x10000 && cp <= 0x10ffff);
        },
 
-       normalizeExtOptions: function(options) {
-               // Normalize whitespace in extension attribute values
-               // Mimics Sanitizer::decodeTagAttributes from the PHP parser
-               for (var i = 0, n = options.length; i < n; i++) {
-                       var o = options[i];
-                       o.v = o.v.trim().replace(/(\s+)/g, ' ');
-               }
-               return options;
-       },
-
        debug_pp: function() {
                var out = [arguments[0]];
                for ( var i = 2; i < arguments.length; i++) {
diff --git a/js/lib/pegTokenizer.pegjs.txt b/js/lib/pegTokenizer.pegjs.txt
index 9014f32..41a6639 100644
--- a/js/lib/pegTokenizer.pegjs.txt
+++ b/js/lib/pegTokenizer.pegjs.txt
@@ -1502,7 +1502,7 @@
                     new KV('name', tagName),
                     new KV('about', "#" + pegArgs.env.newObjectId()),
                     new KV('source', dp.src),
-                    new KV('options', Util.normalizeExtOptions(t2.attribs))
+                    new KV('options', t2.attribs)
                 ], dp);
             } else {
                 // If not a known installed extension, parse content as 
wikitext.

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

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

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

Reply via email to