diff --git a/CHANGELOG.md b/CHANGELOG.md index f358865..454e22f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.22.2] - 2023-10-14 + +### Fixed + +- Escaped backslashes (2 consecutive backslashes) were not appearing correctly in HTML output. e.g a snippet with a `body` of "\\${num};" appears as "\${num}". + +### Changed + +- Modify *webpack.config.js* to work with Node v18.x. It was throwing a ['ERR_OSSL_EVP_UNSUPPORTED' error](https://stackoverflow.com/questions/69394632/webpack-build-failing-with-err-ossl-evp-unsupported) whose cause is: "itโ€™s likely that your application or a module youโ€™re using is attempting to use an algorithm or key size which is no longer allowed by default with OpenSSL 3.0". +- Updated tests in *formatter.test.js*. +- Updated secret for GitHub Action to publish automatically. + ## [0.22.1] - 2022-06-29 ### Fixed diff --git a/README.md b/README.md index a62322d..c6eee52 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ If you have a suggestion or find a bug, please file an issue. ## Show gratitude -If you are happy with the extension: please star the repo, and leave a review to help others find it. ๐ŸŒŸ +If you are happy with the extension: please star the repo, and leave [a review ](https://marketplace.visualstudio.com/items?itemName=robole.snippets-ranger&ssr=false#review-details) in the marketplace to help others find it. ๐ŸŒŸ You can [buy me a coffee or sponsor me](https://ko-fi.com/roboleary) if you would like to support me in maintaining this project and creating more open-source software. ๐Ÿ™ diff --git a/package.json b/package.json index 5eb52c2..cce9ec9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ }, "description": "View and edit all your snippets in one purty place. Yee-haw!", "icon": "img/logo.png", - "version": "0.22.1", + "version": "0.22.2", "engines": { "vscode": "^1.4.0", "node": ">=12.0.0" diff --git a/src/formatter.js b/src/formatter.js index 70636a8..37f56bb 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -38,6 +38,7 @@ class Formatter { .replace(/'/g, "'") .replace(//g, ">") + .replace(/\\/g, "\\") .replace(/\r?\n/g, "
") .replace(/\t/g, " "); @@ -45,13 +46,15 @@ class Formatter { } /** - * Escapes all HTML content in the elements of an array and concatenates it into a string that can be consumed by a web page. Each value is appended with a HTML line break (BR tag). + * Escapes all HTML content in the elements of an array and concatenates it into a string + * that can be consumed by a web page. Each value is appended with a HTML line break (BR tag). * @param {Array} array Array of values */ static escapeBody(array) { let str = ""; array.forEach((element) => { - str += `${Formatter.escapeHtml(element)}
`; + str += Formatter.escapeHtml(element); + str += "
"; }); return str; } diff --git a/src/view.js b/src/view.js index a7742db..dc192a6 100644 --- a/src/view.js +++ b/src/view.js @@ -1,3 +1,4 @@ +/* eslint-disable class-methods-use-this */ // @ts-nocheck // eslint-disable-next-line import/no-unresolved const vscode = require("vscode"); @@ -220,9 +221,10 @@ class View { ${snippet.prefix} ${snippet.name} ${snippet.description}`; - table += `${Formatter.escapeBody(snippet.body)} - ${editButton}${deleteButton} - `; + table += ""; + table += Formatter.escapeBody(snippet.body); + table += ""; + table += `${editButton}${deleteButton}`; }); table += `${tableEnd}`; diff --git a/test/suite/formatter.test.js b/test/suite/formatter.test.js index 055980f..a1de4b7 100644 --- a/test/suite/formatter.test.js +++ b/test/suite/formatter.test.js @@ -42,16 +42,35 @@ describe("Formatter", () => { }); describe("escapeHtml()", () => { - it("should replace anything that could be interpeted as HTML with a text equivalent", () => { + it("should replace html element with a HTML-safe equivalent", () => { let text1 = formatter.escapeHtml(`This is the tag.`); + + assert.strictEqual(text1, "This is the <html> tag."); + }); + + it("should replace single quotes, double quotes, and ampersands with a HTML-safe equivalent", () => { let text2 = formatter.escapeHtml(`No '"& allowed.`); + + assert.strictEqual(text2, "No '"& allowed."); + }); + + it("should replace a tab with a HTML-safe equivalent", () => { let text3 = formatter.escapeHtml(`\t let x = 1;`); - let text4 = formatter.escapeHtml(`Line 1.\r\n`); - assert.strictEqual(text1, "This is the <html> tag."); - assert.strictEqual(text2, "No '"& allowed."); assert.strictEqual(text3, "  let x = 1;"); - assert.strictEqual(text4, "Line 1.
"); + }); + + it("should replace line breaks with a HTML-safe equivalent", () => { + let text1 = formatter.escapeHtml(`Line 1.\r\nLine 2.`); + let text2 = formatter.escapeHtml(`Line 1.\nLine 2.`); + + assert.strictEqual(text1, "Line 1.
Line 2."); + assert.strictEqual(text2, "Line 1.
Line 2."); + }); + + it("should replace an escaped backslash with a HTML-safe equivalent", () => { + let text = formatter.escapeHtml("`\\$num is a variable`;"); + assert.strictEqual(text, "`\\$num is a variable`;"); }); }); }); diff --git a/todo.md b/todo.md index 67ba865..4f018dd 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,7 @@ # To Do +1. Add workspace snippets. +1. Emphasize in readme that it uses the same source files as VS Code. 1. Filter? 1. Search? 1. Show the shortcuts assigned to any snippets (via command 'insert snippet')? diff --git a/webpack.config.js b/webpack.config.js index 17ca03c..f8ecd25 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,6 +3,10 @@ const path = require("path"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin"); +const crypto = require("crypto"); + +const crypto_orig_createHash = crypto.createHash; +crypto.createHash = algorithm => crypto_orig_createHash(algorithm === "md4" ? "sha256" : algorithm); const config = { target: "node",