Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Ensure UTF-8 characters are encoded in \u0XXX notation #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var https = require('https');
var http = require('http');
var jsonStatus = require('./statusmsgs.json');
var url = require('url');
var asciiJSON = require('ascii-json');

module.exports = Plotly;

Expand Down Expand Up @@ -41,8 +42,8 @@ Plotly.prototype.plot = function(data, graphOptions, callback) {
var pack = {
'platform': self.platform,
'version': self.version,
'args': JSON.stringify(data),
'kwargs': JSON.stringify(graphOptions),
'args': asciiJSON.stringify(data),
'kwargs': asciiJSON.stringify(graphOptions),
'un': self.username,
'key': self.apiKey,
'origin': self.origin
Expand Down Expand Up @@ -72,7 +73,7 @@ Plotly.prototype.plot = function(data, graphOptions, callback) {

/* Try to parse the response */
try {
body = JSON.parse(body);
body = asciiJSON.parse(body);
} catch (e) {
callback(e);
}
Expand Down Expand Up @@ -178,7 +179,7 @@ Plotly.prototype.getFigure = function (fileOwner, fileId, callback) {

/* Try to parse the response */
try {
body = JSON.parse(body);
body = asciiJSON.parse(body);
} catch (e) {
callback(e);
}
Expand Down Expand Up @@ -207,7 +208,7 @@ Plotly.prototype.getImage = function (figure, opts, callback) {
if (!figure) return new Error('no figure provided!');

var self = this;
var payload = JSON.stringify({
var payload = asciiJSON.stringify({
figure: figure,
format: opts.format || 'png',
width: opts.width || 700,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"author": "Alexander Daniel <[email protected]> (http://lesinstruments.com/)",
"license": "MIT",
"dependencies": {
"ascii-json": "^0.2.0",
"mkdirp": "~0.5.0"
}
}
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ test('getImage, imageserver error', function (t) {

});

test('getImage with UTF characters', function (t) {
t.plan(2);
var plotly = require('../index')('node-test-account', 'tpmz9ye8hg');

var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
};

var figure = {
'data': [trace1],
'layout': {
'title': 'Title (μ = 0, σ = 1.0)'
}
};

plotly.getImage(figure, {}, function (err, imageData) {
t.error(err);
t.ok(imageData);
t.end();
});
});

test('creates a plot with UTF chars in filename', function (t) {
t.plan(1);

Expand Down