GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #41 from jonschlinkert/fix/CVE-2023-26115-2 · jonschlinkert/word-wrap@420dce9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • index.js
  • package.json
  • test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎index.js‎

Copy file name to clipboardExpand all lines: index.js
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
/*!
22
* word-wrap <https://github.com/jonschlinkert/word-wrap>
33
*
4-
* Copyright (c) 2014-2017, Jon Schlinkert.
4+
* Copyright (c) 2014-2023, Jon Schlinkert.
55
* Released under the MIT License.
66
*/
77

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+
823
module.exports = function(str, options) {
924
options = options || {};
1025
if (str == null) {
@@ -36,7 +51,7 @@ module.exports = function(str, options) {
3651
}).join(newline);
3752

3853
if (options.trim === true) {
39-
result = result.replace(/[ \t]*$/gm, '');
54+
result = trimTabAndSpaces(result);
4055
}
4156
return result;
4257
};
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "word-wrap",
33
"description": "Wrap words to a specified length.",
4-
"version": "1.2.3",
4+
"version": "1.2.4",
55
"homepage": "https://github.com/jonschlinkert/word-wrap",
66
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
77
"contributors": [
Collapse file

‎test.js‎

Copy file name to clipboardExpand all lines: test.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ describe('wrap', function () {
3434
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.');
3535
});
3636

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+
3741
it('should handle strings with just newlines', function () {
3842
assert.equal(wrap('\r\n', {indent: '\r\n', width: 18}), '\r\n');
3943
});

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.