From c7f2c53fbf6ec96460e686a242c4610b413ca238 Mon Sep 17 00:00:00 2001 From: Max Malm Date: Fri, 17 Feb 2017 19:59:12 -0800 Subject: [PATCH] Cast name to String to ensure .match is available Summary: PR for issue #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 https://github.com/facebook/react-native/pull/12447 Differential Revision: D4584041 fbshipit-source-id: 117e76570aa9975ac851192b030c5a77daf19bcc --- react-native-cli/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native-cli/index.js b/react-native-cli/index.js index 795e8143edb..e2ae7586b8f 100755 --- a/react-native-cli/index.js +++ b/react-native-cli/index.js @@ -167,7 +167,7 @@ if (cli) { } function validateProjectName(name) { - if (!name.match(/^[$A-Z_][0-9A-Z_$]*$/i)) { + if (!String(name).match(/^[$A-Z_][0-9A-Z_$]*$/i)) { console.error( '"%s" is not a valid name for a project. Please use a valid identifier ' + 'name (alphanumeric).',