8000 WebAgg issue - Uncaught SyntaxError: Unexpected token & by mdboom · Pull Request #2849 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

WebAgg issue - Uncaught SyntaxError: Unexpected token & #2849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2014

Conversation

mdboom
Copy link
Member
@mdboom mdboom commented Feb 28, 2014

The following code (from http://matplotlib.org/users/pyplot_tutorial.html):

import matplotlib
matplotlib.use('webagg')

import matplotlib.pyplot as plt

plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

launches the Web server and browser pointing to http://127.0.0.1:8988/ OK, however there's an error in the Chrome's Console:

Uncaught SyntaxError: Unexpected token & 

The offending line is:

fig = new figure('1', websocket_url_prefix);

in the main HTML document, which seems to be from this template:

site-packages/matplotlib/backends/web_backend/all_figures.html 

which reads:

fig = new figure({{ repr(str(fig_id)) }}, websocket_url_prefix);

Removing the repr call above solves the issue - is there a reason behind it?

More info:

  • Matplotlib
$ pip show matplotlib

---
Name: matplotlib
Version: 1.3.1
  • Python 2.7.5+
  • Chromium
Version 32.0.1700.107 Ubuntu 13.10 (32.0.1700.107-0ubuntu0.13.10.1~20140204.972.1)

@mdboom
Copy link
Member
mdboom commented Feb 28, 2014

The reason for the repr is that the figure id is a string, so we want it to have quotes around it. This can be done another way, though, I think.

The source of the problem is a change in the behavior of the XML escaping in tornado that changed between tornado 3.1.1 and 3.2.0. From the Tornado Changelog:

xhtml_escape now escapes apostrophes as well.

@mdboom
Copy link
Member
mdboom commented Feb 28, 2014

Fix is attached.

@mdboom mdboom added this to the v1.3.x blocker milestone Feb 28, 2014
@icyrockcom
Copy link
Author

Great, thanks for a quick fix!

tacaswell added a commit that referenced this pull request Mar 3, 2014
WebAgg issue - Uncaught SyntaxError: Unexpected token &
@tacaswell tacaswell merged commit 8863ace into matplotlib:v1.3.x Mar 3, 2014
@mdboom mdboom deleted the webagg/tornado-escape-fix branch August 7, 2014 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0