Page MenuHomePhabricator

SyntaxError: Unexpected token u in JSON at position 0
Closed, ResolvedPublic

Description

This error is coming from ve.dm.MWInlineImageNode.static.toDataElement method. DOM structure which should be parsed is following:

<figure-inline data-cx="{&quot;adapted&quot;:false,&quot;imageSource&quot;:&quot;null&quot;}" data-mw="undefined" id="6" typeof="mw:Image"><span about="#mwt16" id="mwEw"><img src="null"></span></figure-inline>

data-mw attribute from the above structure is extracted into mwDataJSON variable and passed to JSON.parse. Since value of that attribute is "undefined", this check does not catch the problem mwDataJSON ? JSON.parse( mwDataJSON ) : {} and the error occurs:

jQuery.Deferred exception: Unexpected token u in JSON at position 0 SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.ve.dm.MWInlineImageNode.static.toDataElement (http://localhost/extensions/VisualEditor/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js?26093:60:30)
    at VeDmConverter.ve.dm.Converter.createDataElements (http://localhost/extensions/VisualEditor/lib/ve/src/dm/ve.dm.Converter.js?6c22b:560:36)
    at VeDmConverter.ve.dm.Converter.getDataFromDomSubtree (http://localhost/extensions/VisualEditor/lib/ve/src/dm/ve.dm.Converter.js?6c22b:864:30)
    at VeDmConverter.ve.dm.Converter.getDataFromDomSubtree (http://localhost/extensions/VisualEditor/lib/ve/src/dm/ve.dm.Converter.js?6c22b:990:13)
    at VeDmConverter.ve.dm.Converter.getDataFromDomSubtree (http://localhost/extensions/VisualEditor/lib/ve/src/dm/ve.dm.Converter.js?6c22b:990:13)
    at VeDmConverter.ve.dm.Converter.getModelFromDom (http://localhost/extensions/VisualEditor/lib/ve/src/dm/ve.dm.Converter.js?6c22b:634:14)
    at VeInitMwCXTarget.ve.init.mw.CXTarget.setSectionContent (http://localhost/extensions/ContentTranslation/modules/ve-cx/init/ve.init.mw.CXTarget.js?a7c07:730:29)
    at VeInitMwCXTarget.<anonymous> (http://localhost/extensions/ContentTranslation/modules/ve-cx/init/ve.init.mw.CXTarget.js?a7c07:841:8)
    at mightThrow (http://localhost/load.php?debug=true&lang=en&modules=jquery%7Cmediawiki.base&only=scripts&skin=vector&version=0owlbb8:3583:29) undefined
This was caught when translating the first paragraph of en:Paris into Spanish.

Event Timeline

Diagnosis:

Original HTML from restbase:

image.png (497×865 px, 68 KB)

The source section HTML in this case is as follows:

<section id="cxTargetSection1" data-mw-cx-source="undefined">
    <p id="mwEA">
        <span data-segmentid="4" class="cx-segment">
            <b id="mwEQ">Paris</b> (
            <small about="#mwt16" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;IPA-fr&quot;,&quot;href&quot;:&quot;./Template:IPA-fr&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;paʁi&quot;},&quot;3&quot;:{&quot;wt&quot;:&quot;Paris1.ogg&quot;}},&quot;i&quot;:0}}]}"
                id="mwEg" typeof="mw:Transclusion" data-ve-no-generated-contents="true">French pronunciation:
                <span typeof="mw:Entity">&nbsp;</span>
                <span typeof="mw:Entity"></span>
            </small>
            <small about="#mwt16" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;IPA-fr&quot;,&quot;href&quot;:&quot;./Template:IPA-fr&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;paʁi&quot;},&quot;3&quot;:{&quot;wt&quot;:&quot;Paris1.ogg&quot;}},&quot;i&quot;:0}}]}"
                id="mwEg" typeof="mw:Transclusion" data-ve-ignore="true"></small>
            <span about="#mwt16" class="IPA" title="Representation in the International Phonetic Alphabet (IPA)"
                data-ve-ignore="true">
                <a class="cx-link" data-linkid="5" href="./Help:IPA/French" rel="mw:WikiLink" title="Help:IPA/French">[paʁi]</a>
            </span>
            <small about="#mwt16" class="nowrap" id="mwEw" data-ve-ignore="true">
                <span typeof="mw:Entity">&nbsp;</span>(</small>
        </span>
        <figure-inline typeof="mw:Image" data-mw="undefined" id="6">
            <span about="#mwt16" id="mwEw">
                <img src="null">
            </span>
        </figure-inline>
        <span data-segmentid="8" class="cx-segment">
            <small about="#mwt16" class="nowrap" id="mwEw">
                <span class="unicode haudio">
                    <span class="fn">
                        <span style="white-space:nowrap">
                            <span typeof="mw:Entity">&nbsp;</span>
                        </span>
                        <a href="//upload.wikimedia.org/wikipedia/commons/2/2c/Paris1.ogg" rel="mw:ExtLink" title="Paris1.ogg">listen</a>
                    </span>
                </span>)</small>) is the

There is a bug about where we close the first segment. It is just above the figure-inline tag. Figure-inline should go inside the first segment. Which is tricky because of mutli-part template situation here. The fix will be at cxserver lineardoc module to correctly understand transclusion context. That part in cxserver is repeatedly proving fragile :(

Also, look at the repeatation of <small about="#mwt16" data-mw=" in the above example.

Change 445594 had a related patch set uploaded (by Santhosh; owner: Santhosh):
[mediawiki/services/cxserver@master] Remove duplicated inline templates appearing in parsed content

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

Change 445980 had a related patch set uploaded (by Santhosh; owner: Santhosh):
[mediawiki/services/cxserver@master] Define figure-inline as inline tag for the parser

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

Change 446575 had a related patch set uploaded (by Santhosh; owner: Santhosh):
[mediawiki/extensions/VisualEditor@master] ve.dm.MWInlineImageNode: Fix undefined data-mw in toDomElements output

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

Change 446575 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] ve.dm.MWInlineImageNode: Fix undefined data-mw in toDomElements output

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

Change 445594 merged by jenkins-bot:
[mediawiki/services/cxserver@master] Remove duplicated inline templates appearing in parsed content

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

Change 445980 merged by jenkins-bot:
[mediawiki/services/cxserver@master] Define figure-inline as inline tag for the parser

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

Mentioned in SAL (#wikimedia-operations) [2018-07-24T05:29:52Z] <kartik@deploy1001> Started deploy [cxserver/deploy@d378d27]: Update cxserver to d3c9d15 (T198941)

Mentioned in SAL (#wikimedia-operations) [2018-07-24T05:33:53Z] <kartik@deploy1001> Finished deploy [cxserver/deploy@d378d27]: Update cxserver to d3c9d15 (T198941) (duration: 04m 01s)

Change 447653 had a related patch set uploaded (by Bartosz Dziewoński; owner: Santhosh):
[mediawiki/extensions/VisualEditor@wmf/1.32.0-wmf.13] ve.dm.MWInlineImageNode: Fix undefined data-mw in toDomElements output

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

Change 447653 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@wmf/1.32.0-wmf.13] ve.dm.MWInlineImageNode: Fix undefined data-mw in toDomElements output

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

Mentioned in SAL (#wikimedia-operations) [2018-07-25T23:35:02Z] <thcipriani@deploy1001> Synchronized php-1.32.0-wmf.13/extensions/VisualEditor/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js: SWAT: [[gerrit:447653|ve.dm.MWInlineImageNode: Fix undefined data-mw in toDomElements output]] T198941 T200214 (duration: 00m 57s)