mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Symbol import: preemptively error on non-utf8 symbols
Summary: Put a test somewhere we can --ignore it. Also fix path tests. Test Plan: insert good/bad values at various positions. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Differential Revision: https://secure.phabricator.com/D8353
This commit is contained in:
parent
cd080b092e
commit
361e49dd67
1 changed files with 21 additions and 24 deletions
|
@ -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 ".
|
||||
|
|
Loading…
Reference in a new issue