Skip to content

Commit 361e49d

Browse files
aviveyepriestley
authored and
epriestley
committedFeb 26, 2014
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
1 parent cd080b0 commit 361e49d

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed
 

‎scripts/symbols/import_project_symbols.php

+21-24
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ function commit_symbols ($syms, $project, $no_purge) {
106106

107107
}
108108

109+
function check_string_value($value, $field_name, $line_no, $max_length) {
110+
if (strlen($value) > $max_length) {
111+
throw new Exception(
112+
"{$field_name} '{$value}' defined on line #{$line_no} is too long, ".
113+
"maximum {$field_name} length is {$max_length} characters.");
114+
}
115+
116+
if (!phutil_is_utf8_with_only_bmp_characters($value)) {
117+
throw new Exception(
118+
"{$field_name} '{$value}' defined on line #{$line_no} is not a valid ".
119+
"UTF-8 string, ".
120+
"it should contain only UTF-8 characters.");
121+
}
122+
}
123+
109124
$no_purge = $args->getArg('no-purge');
110125
$symbols = array();
111126
foreach ($input as $key => $line) {
@@ -137,31 +152,13 @@ function commit_symbols ($syms, $project, $no_purge) {
137152
$line_number = $matches['line'];
138153
$path = $matches['path'];
139154

140-
if (strlen($context) > 128) {
141-
throw new Exception(
142-
"Symbol context '{$context}' defined on line #{$line_no} is too long, ".
143-
"maximum symbol context length is 128 characters.");
144-
}
145-
146-
if (strlen($name) > 128) {
147-
throw new Exception(
148-
"Symbol name '{$name}' defined on line #{$line_no} is too long, ".
149-
"maximum symbol name length is 128 characters.");
150-
}
151-
152-
if (strlen($type) > 12) {
153-
throw new Exception(
154-
"Symbol type '{$type}' defined on line #{$line_no} is too long, ".
155-
"maximum symbol type length is 12 characters.");
156-
}
157-
158-
if (strlen($lang) > 32) {
159-
throw new Exception(
160-
"Symbol language '{$lang}' defined on line #{$line_no} is too long, ".
161-
"maximum symbol language length is 32 characters.");
162-
}
155+
check_string_value($context, 'Symbol context', $line_no, 128);
156+
check_string_value($name, 'Symbol name', $line_no, 128);
157+
check_string_value($type, 'Symbol type', $line_no, 12);
158+
check_string_value($lang, 'Symbol language', $line_no, 32);
159+
check_string_value($path, 'Path', $line_no, 512);
163160

164-
if (!strlen($path) || $path[0] != 0) {
161+
if (!strlen($path) || $path[0] != '/') {
165162
throw new Exception(
166163
"Path '{$path}' defined on line #{$line_no} is invalid. Paths should ".
167164
"begin with '/' and specify a path from the root of the project, like ".

0 commit comments

Comments
 (0)
Failed to load comments.