Skip to content

Commit 0982b87

Browse files
authored
Merge pull request #14 from mustilica/handlenonasciicomments
Handle non-ascii characters in comment.
2 parents 51ef4c9 + b763553 commit 0982b87

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

assets/js/app.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const PythonShell = require("python-shell");
44
const terminate = require("terminate");
55
const dialog = require("electron").remote.require("electron").dialog;
66
const ipcRenderer = require("electron").ipcRenderer;
7+
const jsesc = require('jsesc');
78

89
var instapyPath = "";
910
var pyshell;
@@ -242,7 +243,20 @@ var app = {
242243
value = `'${media.commentsMedia}'`;
243244
}
244245

245-
content = `\nsession.set_do_comment(enabled=True, percentage=${data.commentsPercent})\nsession.set_comments([${data.comments}], media=${value})`;
246+
// Escape to handle non-ascii input.
247+
var escapedComments = jsesc(data.comments, {
248+
'quotes': 'double'
249+
})
250+
251+
// Add `u`(Python unicode indentifier) beginning of each comment.
252+
escapedComments =
253+
'u' +
254+
escapedComments
255+
.replace(/\s+/g, "")
256+
.split("',")
257+
.join("', u");
258+
259+
content = `\nsession.set_do_comment(enabled=True, percentage=${data.commentsPercent})\nsession.set_comments([${escapedComments}], media=${value})`;
246260
}
247261

248262
return content;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"fs-jetpack": "^1.2.0",
3434
"jquery": "^3.2.1",
3535
"python-shell": "^0.4.0",
36-
"terminate": "^2.1.0"
36+
"terminate": "^2.1.0",
37+
"jsesc": "^0.3.0"
3738
},
3839
"build": {
3940
"appId": "com.ahmadudin.instapygui",

0 commit comments

Comments
 (0)