diff --git a/scripts/symbols/import_project_symbols.php b/scripts/symbols/import_project_symbols.php index 2f970182c2..d2946e8ef6 100755 --- a/scripts/symbols/import_project_symbols.php +++ b/scripts/symbols/import_project_symbols.php @@ -106,6 +106,21 @@ function commit_symbols ($syms, $project, $no_purge) { } +function check_string_value($value, $field_name, $line_no, $max_length) { + if (strlen($value) > $max_length) { + throw new Exception( + "{$field_name} '{$value}' defined on line #{$line_no} is too long, ". + "maximum {$field_name} length is {$max_length} characters."); + } + + if (!phutil_is_utf8_with_only_bmp_characters($value)) { + throw new Exception( + "{$field_name} '{$value}' defined on line #{$line_no} is not a valid ". + "UTF-8 string, ". + "it should contain only UTF-8 characters."); + } +} + $no_purge = $args->getArg('no-purge'); $symbols = array(); foreach ($input as $key => $line) { @@ -137,31 +152,13 @@ foreach ($input as $key => $line) { $line_number = $matches['line']; $path = $matches['path']; - if (strlen($context) > 128) { - throw new Exception( - "Symbol context '{$context}' defined on line #{$line_no} is too long, ". - "maximum symbol context length is 128 characters."); - } + check_string_value($context, 'Symbol context', $line_no, 128); + check_string_value($name, 'Symbol name', $line_no, 128); + check_string_value($type, 'Symbol type', $line_no, 12); + check_string_value($lang, 'Symbol language', $line_no, 32); + check_string_value($path, 'Path', $line_no, 512); - if (strlen($name) > 128) { - throw new Exception( - "Symbol name '{$name}' defined on line #{$line_no} is too long, ". - "maximum symbol name length is 128 characters."); - } - - if (strlen($type) > 12) { - throw new Exception( - "Symbol type '{$type}' defined on line #{$line_no} is too long, ". - "maximum symbol type length is 12 characters."); - } - - if (strlen($lang) > 32) { - throw new Exception( - "Symbol language '{$lang}' defined on line #{$line_no} is too long, ". - "maximum symbol language length is 32 characters."); - } - - if (!strlen($path) || $path[0] != 0) { + if (!strlen($path) || $path[0] != '/') { throw new Exception( "Path '{$path}' defined on line #{$line_no} is invalid. Paths should ". "begin with '/' and specify a path from the root of the project, like ".