GeezerVison is showing github.com — Merge pull request #41 from jonschlinkert/fix/CVE-2023-26115-2 · jonschlinkert/word-wrap@420dce9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: index.js +17-2Lines changed: 17 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /*! | 2 | 2 | * word-wrap <https://github.com/jonschlinkert/word-wrap> | 3 | 3 | * | 4 | | - * Copyright (c) 2014-2017, Jon Schlinkert. | | 4 | + * Copyright (c) 2014-2023, Jon Schlinkert. | 5 | 5 | * Released under the MIT License. | 6 | 6 | */ | 7 | 7 |
| | 8 | +function trimEnd(str) { | | 9 | + let lastCharPos = str.length - 1; | | 10 | + let lastChar = str[lastCharPos]; | | 11 | + while(lastChar === ' ' || lastChar === '\t') { | | 12 | + lastChar = str[--lastCharPos]; | | 13 | + } | | 14 | + return str.substring(0, lastCharPos + 1); | | 15 | +} | | 16 | + | | 17 | +function trimTabAndSpaces(str) { | | 18 | + const lines = str.split('\n'); | | 19 | + const trimmedLines = lines.map((line) => trimEnd(line)); | | 20 | + return trimmedLines.join('\n'); | | 21 | +} | | 22 | + | 8 | 23 | module.exports = function(str, options) { | 9 | 24 | options = options || {}; | 10 | 25 | if (str == null) { | @@ -36,7 +51,7 @@ module.exports = function(str, options) { | 36 | 51 | }).join(newline); | 37 | 52 |
| 38 | 53 | if (options.trim === true) { | 39 | | - result = result.replace(/[ \t]*$/gm, ''); | | 54 | + result = trimTabAndSpaces(result); | 40 | 55 | } | 41 | 56 | return result; | 42 | 57 | }; | |
Collapse file Copy file name to clipboardExpand all lines: package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "name": "word-wrap", | 3 | 3 | "description": "Wrap words to a specified length.", | 4 | | - "version": "1.2.3", | | 4 | + "version": "1.2.4", | 5 | 5 | "homepage": "https://github.com/jonschlinkert/word-wrap", | 6 | 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | 7 | 7 | "contributors": [ | |
Collapse file Copy file name to clipboardExpand all lines: test.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,10 @@ describe('wrap', function () { | 34 | 34 | assert.equal(wrap(str, {trim: true}), 'A project without documentation is like a project\nthat doesn\'t exist. Verb solves this by making it\ndead simple to generate project documentation,\nusing simple markdown templates, with zero\nconfiguration required.'); | 35 | 35 | }); | 36 | 36 |
| | 37 | + it('should trim trailing whitespace (even for empty lines):', function () { | | 38 | + assert.equal(wrap("a \n\nb \n \nc\t", {trim: true}), 'a\n\nb\n\nc'); | | 39 | + }); | | 40 | + | 37 | 41 | it('should handle strings with just newlines', function () { | 38 | 42 | assert.equal(wrap('\r\n', {indent: '\r\n', width: 18}), '\r\n'); | 39 | 43 | }); | |
|