Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 361e49dd67994bae8bc73dbb1c9ef6c3050e1f35 1 parent cd080b0
@avivey avivey authored epriestley committed
Showing with 21 additions and 24 deletions.
  1. +21 −24 scripts/symbols/import_project_symbols.php
View
45 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 @@ function commit_symbols ($syms, $project, $no_purge) {
$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.");
- }
-
- 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.");
- }
+ 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($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 ".
Please sign in to comment.
Something went wrong with that request. Please try again.