module: standardize strip shebang behaviour#12202
module: standardize strip shebang behaviour#12202seppevs wants to merge 1 commit intonodejs:masterfrom
Conversation
lib/internal/module.js
Outdated
There was a problem hiding this comment.
Style nit: two more spaces of indent.
When loading a module, Node needs to finds the end of a shebang comment by searching for a \r or \n character. This behaviour is now standardized into a dedicated internal module function Refs: nodejs#12180
fef91db to
355449d
Compare
| if (contLen === 2) { | ||
| // Exact match | ||
| content = ''; | ||
| } else { |
There was a problem hiding this comment.
You could just drop the if (contLen === 2) case, it should almost never be hit.
cjihrig
left a comment
There was a problem hiding this comment.
LGTM, but I think we should add a test.
| /** | ||
| * Find end of shebang line and slice it off | ||
| */ | ||
| function stripShebang(content) { |
There was a problem hiding this comment.
stripHashBang() would be clearer
There was a problem hiding this comment.
Shebang is more commonly used. For example, the Hashbang article on Wikipedia redirects to the Shebang article.
There was a problem hiding this comment.
As a single data point: I've been a UNIX user for 20+ years and this is the first time I've heard someone call it a hashbang.
| // Remove shebang | ||
| var contLen = content.length; | ||
| if (contLen >= 2) { | ||
| if (content.charCodeAt(0) === 35/*#*/ && |
There was a problem hiding this comment.
does this lint? I would expect a space after 35
There was a problem hiding this comment.
Yes it does. This code originates from lib/module.js (see master branch)
|
The implementation looks good to me, but I think this should have a regression test for the issue in #12180. |
|
Ping @seppevs – do you think you could add a test here? or, the other way around: @not-an-aardvark would you be okay with landing this and keeping #12180 open until we have a test? It would seem like an acceptable second or slightly adventurous first contribution for next week’s Code & Learn. |
Sounds good to me. |
|
Landed in f971566 |
When loading a module, Node needs to finds the end of a shebang comment by searching for a \r or \n character. This behaviour is now standardized into a dedicated internal module function Refs: #12180 PR-URL: #12202 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
Opting to leave to bake until this has tests. |
When loading a module, Node needs to finds the end of a shebang comment by searching for a
\ror\ncharacter. This behaviour is now standardized into a dedicated internal module functionRefs: #12180
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
module