Page MenuHomePhabricator

cargo_display_map SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Closed, ResolvedPublic

Description

It's more a problem with the parser, but brought about by Cargo so forgive me if I'm adding against the wrong project.

If {{#cargo_display_map}} is used inline, then the JSON.parse error above is raised. This is because with this wikitext:

* Coordinates:  {{#if: {{{coordinates|}}} |  {{{coordinates}}} {{#cargo_display_map: |point={{{coordinates|}}} |width=800 }} }}

This sort of HTML is produced:

<li> Coordinates:  -32.066229, 115.76116 	<div style="height: 400px; width: 800px" class="mapCanvas" id="mapCanvas1"></li></ul>
		<div class="cargoMapData" style="display: none" mappingservice="OpenLayers">[{"name":-32.066229,"title":null,"lat":-32.066229,"lon":115.76116,"otherValues":[]}]</div>
	</div>

Which confuses JSON.parse for some weird reason. If the wikitext is given a couple of newlines:

* Coordinates:  {{#if: {{{coordinates|}}} |  {{{coordinates}}}

{{#cargo_display_map: |point={{{coordinates|}}} |width=800 }} }}

Everything's fine.

I wondered if perhaps the cargoMapData could instead be defined as a JS variable, and so avoid the need of parsing?

Event Timeline

Vvjjkkii renamed this task from cargo_display_map SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data to rebaaaaaaa.Jul 1 2018, 1:05 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
Oetterer renamed this task from rebaaaaaaa to cargo_display_map SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data.Jul 1 2018, 6:21 AM
Oetterer raised the priority of this task from High to Needs Triage.
Oetterer updated the task description. (Show Details)
Oetterer added a subscriber: Aklapper.

Change 445332 had a related patch set uploaded (by Samwilson; owner: Samwilson):
[mediawiki/extensions/Cargo@master] Use span for mapdata to prevent breaking when used inline

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

Change 445332 merged by jenkins-bot:
[mediawiki/extensions/Cargo@master] Use span for mapdata to prevent breaking when used inline

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