Skip to content

fix: regexes are more consistent with sed and grep#303

Merged
ariporad merged 1 commit intoshelljs:masterfrom
nfischer:more-regex-tests
Jan 24, 2016
Merged

fix: regexes are more consistent with sed and grep#303
ariporad merged 1 commit intoshelljs:masterfrom
nfischer:more-regex-tests

Conversation

@nfischer
Copy link
Copy Markdown
Member

sed() will now convert search strings to regex form, so 'a*' will now work like /a*/. Also, new tests for grep and sed ensure that * is not expanded for filename globbing.

While the filename globbing isn't currently an issue, I anticipate that it could be a problem if we don't handle sed() and grep() carefully when doing filename globbing as part of the wrap() function (which I think is the way this project should go). These tests are an extra guard to make sure we don't make any mistakes.

So this should probably be merged before #275 to be safe.

@nfischer nfischer added fix Bug/defect, or a fix for such a problem medium priority labels Jan 24, 2016
src/sed.js Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Slight Nitpick]: Maybe just simplify to:

var result = fs.readFileSync(file, 'utf8').split('\n').map(function (line) {
    return line.replace(regex, replacement);
}).join('\n');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I originally wrote it like that. I switched it because I thought we might later want to modify sed to return a list (similar what ls() does) instead of return a multi line string. I can revert this back though

@ariporad
Copy link
Copy Markdown
Contributor

One small nitpick, but otherwise LGTM!

@ariporad ariporad assigned nfischer and unassigned ariporad Jan 24, 2016
sed will now convert search strings to regex form, so `'a*'` will now work like
`/a*/`. Also, new tests for grep and sed ensure that '*' is not expanded for
filename globbing.
@nfischer
Copy link
Copy Markdown
Member Author

@ariporad updated to address your comment. Feel free to merge once tests pass.

ariporad added a commit that referenced this pull request Jan 24, 2016
fix: regexes are more consistent with sed and grep
@ariporad ariporad merged commit 154d6a6 into shelljs:master Jan 24, 2016
@ariporad
Copy link
Copy Markdown
Contributor

Merged

@ariporad ariporad added this to the v0.6.0 milestone Jan 24, 2016
@nfischer nfischer deleted the more-regex-tests branch January 24, 2016 22:37
@nfischer nfischer mentioned this pull request Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug/defect, or a fix for such a problem medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants