Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethanfann/remove trim off newlines dependency #2825

Conversation

ethanfann
Copy link

@ethanfann ethanfann commented Sep 7, 2021

In response to https://nvd.nist.gov/vuln/detail/CVE-2021-23425, this PR removes the https://www.npmjs.com/package/trim-off-newlines package in favor of a utility function.

Tests have been added to test/helpers/trim-off-newlines.js test/trim-off-newlines/test.js with various cases related to Windows, Mac, and Linux operating systems.

Some test failures are occurring with test-tap/integration/watcher.js, however, I do not know if they are related to the removal of the previous trim packages library in favor of the current. Please let me know if there is a case that the new function isn't handling.

@@ -0,0 +1,4 @@
export default function trimOffNewlines(text) {
const regex = '/^[\r\n]+|[\r\n]+$/g';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a regex literal and just put it inline in the replace call.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR with your suggestion 👍

Comment on lines 1 to 3
import test from '@ava/test';

import trimOffNewlines from '../../lib/trim-off-newlines.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import test from '@ava/test';
import trimOffNewlines from '../../lib/trim-off-newlines.js';
import test from '@ava/test';
import trimOffNewlines from '../../lib/trim-off-newlines.js';

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've update the PR with your suggestion 👍

@KillyMXI
Copy link
Contributor

KillyMXI commented Sep 9, 2021

Tests seem weird. As if it expected to remove all newlines while the regex is only to trim them from both ends of a string.
Looks like some expectations are wrong.

(I'm looking from mobile atm so I might be wrong, sorry if that's the case.)

Upd:
I definitely can't see these tests passing. Desired output has to have inner newlines or the regex is simply [\r\n]+ to remove all newlines, depending on what you actually need.

> '\na\nb \n c\n'.replace(/^[\r\n]+|[\r\n]+$/g, '')
< 'a\nb \n c'
> '\na\nb \n c\n'.replace(/[\r\n]+/g, '')
< 'ab  c'

@ethanfann
Copy link
Author

Thanks @KillyMXI! You're right. Not only was the test faulty, the test file wasn't even being picked up when the suite ran. Apologies for this and I've updated the PR with the fixed tests.

@KillyMXI
Copy link
Contributor

KillyMXI commented Sep 9, 2021

I'd still keep a test for inner newlines being unaffected though.

@ethanfann
Copy link
Author

Added tests with inner newlines 👍

@novemberborn
Copy link
Member

@ethanfann thanks for the PR! I had a look at where / how we use this dependency and I reckon we can remove it entirely. See #2826.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants