From 287c3a82232832c9762aeccbd1ed688e8d837c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sun, 26 Nov 2017 17:34:28 -0500 Subject: [PATCH] Avoid escaping quotes whenever possible Our `.eslintrc.yml` configuration file already allows for avoiding escape (see [ESLint doc for `avoidEscape`](https://eslint.org/docs/rules/quotes#avoidescape)) so we might as well use it. We already use this in a few places I believe. --- client/js/libs/handlebars/parse.js | 2 +- src/identification.js | 10 +-- src/plugins/irc-events/link.js | 12 ++-- test/client/js/libs/handlebars/parse.js | 90 ++++++++++++------------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/client/js/libs/handlebars/parse.js b/client/js/libs/handlebars/parse.js index 0bccaa1d..3b2c2d41 100644 --- a/client/js/libs/handlebars/parse.js +++ b/client/js/libs/handlebars/parse.js @@ -37,7 +37,7 @@ function createFragment(fragment) { attributes += `;background-color:#${fragment.hexBgColor}`; } - attributes += "\""; + attributes += '"'; } if (attributes.length) { diff --git a/src/identification.js b/src/identification.js index 8ea51fe7..1c953520 100644 --- a/src/identification.js +++ b/src/identification.js @@ -90,11 +90,11 @@ class Identification { let file = "# Warning: file generated by The Lounge: changes will be overwritten!\n"; this.connections.forEach((connection) => { - file += "to " + connection.socket.remoteAddress - + " lport " + connection.socket.localPort - + " from " + connection.socket.localAddress - + " fport " + connection.socket.remotePort - + " { reply \"" + connection.user + "\" }\n"; + file += `to ${connection.socket.remoteAddress}` + + ` lport ${connection.socket.localPort}` + + ` from ${connection.socket.localAddress}` + + ` fport ${connection.socket.remotePort}` + + ` { reply "${connection.user}" }\n`; }); fs.writeFile(this.oidentdFile, file, {flag: "w+"}, function(err) { diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index c4aaa836..464e456d 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -53,17 +53,17 @@ function parse(msg, preview, res, client) { var $ = cheerio.load(res.data); preview.type = "link"; preview.head = - $("meta[property=\"og:title\"]").attr("content") + $('meta[property="og:title"]').attr("content") || $("title").text() || ""; preview.body = - $("meta[property=\"og:description\"]").attr("content") - || $("meta[name=\"description\"]").attr("content") + $('meta[property="og:description"]').attr("content") + || $('meta[name="description"]').attr("content") || ""; preview.thumb = - $("meta[property=\"og:image\"]").attr("content") - || $("meta[name=\"twitter:image:src\"]").attr("content") - || $("link[rel=\"image_src\"]").attr("href") + $('meta[property="og:image"]').attr("content") + || $('meta[name="twitter:image:src"]').attr("content") + || $('link[rel="image_src"]').attr("href") || ""; if (preview.thumb.length) { diff --git a/test/client/js/libs/handlebars/parse.js b/test/client/js/libs/handlebars/parse.js index 2c08f8f2..e6bc1f32 100644 --- a/test/client/js/libs/handlebars/parse.js +++ b/test/client/js/libs/handlebars/parse.js @@ -9,8 +9,8 @@ describe("parse Handlebars helper", () => { input: "", expected: "<img onerror='location.href="//youtube.com"'>", }, { - input: "#&\">bug", - expected: "#&">bug", + input: '#&">bug', + expected: '#&">bug', }]; const actual = testCases.map((testCase) => parse(testCase.input)); @@ -35,20 +35,20 @@ describe("parse Handlebars helper", () => { const testCases = [{ input: "irc://freenode.net/thelounge", expected: - "" + + '' + "irc://freenode.net/thelounge" + "", }, { input: "www.nooooooooooooooo.com", expected: - "" + + '' + "www.nooooooooooooooo.com" + "", }, { input: "look at https://thelounge.github.io/ for more information", expected: "look at " + - "" + + '' + "https://thelounge.github.io/" + "" + " for more information", @@ -56,14 +56,14 @@ describe("parse Handlebars helper", () => { input: "use www.duckduckgo.com for privacy reasons", expected: "use " + - "" + + '' + "www.duckduckgo.com" + "" + " for privacy reasons", }, { input: "svn+ssh://example.org", expected: - "" + + '' + "svn+ssh://example.org" + "", }]; @@ -79,7 +79,7 @@ describe("parse Handlebars helper", () => { "bonuspunkt: your URL parser misparses this URL: https://msdn.microsoft.com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx"; const correctResult = "bonuspunkt: your URL parser misparses this URL: " + - "" + + '' + "https://msdn.microsoft.com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx" + ""; @@ -93,7 +93,7 @@ describe("parse Handlebars helper", () => { input: "", expected: "<" + - "" + + '' + "https://theos.kyriasis.com/~kyrias/stats/archlinux.html" + "" + ">", @@ -101,20 +101,20 @@ describe("parse Handlebars helper", () => { input: "abc (www.example.com)", expected: "abc (" + - "" + + '' + "www.example.com" + "" + ")", }, { input: "http://example.com/Test_(Page)", expected: - "" + + '' + "http://example.com/Test_(Page)" + "", }, { input: "www.example.com/Test_(Page)", expected: - "" + + '' + "www.example.com/Test_(Page)" + "", }]; @@ -144,40 +144,40 @@ describe("parse Handlebars helper", () => { const testCases = [{ input: "#a", expected: - "" + + '' + "#a" + "", }, { input: "#test", expected: - "" + + '' + "#test" + "", }, { input: "#äöü", expected: - "" + + '' + "#äöü" + "", }, { input: "inline #channel text", expected: "inline " + - "" + + '' + "#channel" + "" + " text", }, { input: "#1,000", expected: - "" + + '' + "#1,000" + "", }, { input: "@#a", expected: "@" + - "" + + '' + "#a" + "", }]; @@ -206,35 +206,35 @@ describe("parse Handlebars helper", () => { it("should style like mirc", () => { const testCases = [{ input: "\x02bold", - expected: "bold", + expected: 'bold', }, { input: "\x038yellowText", - expected: "yellowText", + expected: 'yellowText', }, { input: "\x030,0white,white", - expected: "white,white", + expected: 'white,white', }, { input: "\x034,8yellowBGredText", - expected: "yellowBGredText", + expected: 'yellowBGredText', }, { input: "\x1ditalic", - expected: "italic", + expected: 'italic', }, { input: "\x1funderline", - expected: "underline", + expected: 'underline', }, { input: "\x02bold\x038yellow\x02nonBold\x03default", expected: - "bold" + - "yellow" + - "nonBold" + + 'bold' + + 'yellow' + + 'nonBold' + "default", }, { input: "\x02bold\x02 \x02bold\x02", expected: - "bold" + + 'bold' + " " + - "bold", + 'bold', }]; const actual = testCases.map((testCase) => parse(testCase.input)); @@ -247,19 +247,19 @@ describe("parse Handlebars helper", () => { const testCases = [{ input: "\x02irc\x0f://\x1dfreenode.net\x0f/\x034,8thelounge", expected: - "" + - "irc" + + '' + + 'irc' + "://" + - "freenode.net" + + 'freenode.net' + "/" + - "thelounge" + + 'thelounge' + "", }, { input: "\x02#\x038,9thelounge", expected: - "" + - "#" + - "thelounge" + + '' + + '#' + + 'thelounge' + "", }]; @@ -271,11 +271,11 @@ describe("parse Handlebars helper", () => { it("should optimize generated html", () => { const testCases = [{ - input: "test \x0312#\x0312\x0312\"te\x0312st\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312a", + input: 'test \x0312#\x0312\x0312"te\x0312st\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312a', expected: "test " + - "" + - "#"testa" + + '' + + '#"testa' + "", }]; @@ -290,14 +290,14 @@ describe("parse Handlebars helper", () => { input: "like..http://example.com", expected: "like.." + - "" + + '' + "http://example.com" + "", }, { input: "like..HTTP://example.com", expected: "like.." + - "" + + '' + "HTTP://example.com" + "", }]; @@ -312,7 +312,7 @@ describe("parse Handlebars helper", () => { const testCases = [{ input: "http://example.com/#hash", expected: - "" + + '' + "http://example.com/#hash" + "", }]; @@ -328,8 +328,8 @@ describe("parse Handlebars helper", () => { const actual = parse(input); expect(actual).to.equal( - "Url: http://example.com/path " + - "Channel: ##channel" + 'Url: http://example.com/path ' + + 'Channel: ##channel' ); }); @@ -338,7 +338,7 @@ describe("parse Handlebars helper", () => { const actual = parse(input); expect(actual).to.equal( - "" + + '' + "#test-https://example.com" + "" );