Skip to content

Commit c7f2c53

Browse files
benjickfacebook-github-bot
authored andcommitted
Cast name to String to ensure .match is available
Summary: PR for issue facebook#12444 In `validateProjectName` in `react-native-cli` `name.match` is called but it's not certain that `name`is a String. This casts `name`to a String before doing the match. I didn't find any tests for this file so I didn't add any. Reproduce: ``` cd react-native-cli npm install node index.js init 123 ``` Before this PR the code throws an exception, after this PR the intended `console.error` is printed. Closes facebook#12447 Differential Revision: D4584041 fbshipit-source-id: 117e76570aa9975ac851192b030c5a77daf19bcc
1 parent cb68b97 commit c7f2c53

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

react-native-cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ if (cli) {
167167
}
168168

169169
function validateProjectName(name) {
170-
if (!name.match(/^[$A-Z_][0-9A-Z_$]*$/i)) {
170+
if (!String(name).match(/^[$A-Z_][0-9A-Z_$]*$/i)) {
171171
console.error(
172172
'"%s" is not a valid name for a project. Please use a valid identifier ' +
173173
'name (alphanumeric).',

0 commit comments

Comments
 (0)