1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +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:
Aviv Eyal 2014-02-26 12:41:55 -08:00 committed by epriestley
parent cd080b092e
commit 361e49dd67

View file

@ -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'); $no_purge = $args->getArg('no-purge');
$symbols = array(); $symbols = array();
foreach ($input as $key => $line) { foreach ($input as $key => $line) {
@ -137,31 +152,13 @@ foreach ($input as $key => $line) {
$line_number = $matches['line']; $line_number = $matches['line'];
$path = $matches['path']; $path = $matches['path'];
if (strlen($context) > 128) { check_string_value($context, 'Symbol context', $line_no, 128);
throw new Exception( check_string_value($name, 'Symbol name', $line_no, 128);
"Symbol context '{$context}' defined on line #{$line_no} is too long, ". check_string_value($type, 'Symbol type', $line_no, 12);
"maximum symbol context length is 128 characters."); check_string_value($lang, 'Symbol language', $line_no, 32);
} check_string_value($path, 'Path', $line_no, 512);
if (strlen($name) > 128) { if (!strlen($path) || $path[0] != '/') {
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) {
throw new Exception( throw new Exception(
"Path '{$path}' defined on line #{$line_no} is invalid. Paths should ". "Path '{$path}' defined on line #{$line_no} is invalid. Paths should ".
"begin with '/' and specify a path from the root of the project, like ". "begin with '/' and specify a path from the root of the project, like ".