Page MenuHomePhabricator

D8353.diff
No OneTemporary

D8353.diff

Index: scripts/symbols/import_project_symbols.php
===================================================================
--- scripts/symbols/import_project_symbols.php
+++ scripts/symbols/import_project_symbols.php
@@ -106,6 +106,21 @@
}
+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 @@
$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 ".

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 28, 11:56 AM (6 d, 8 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7226543
Default Alt Text
D8353.diff (2 KB)

Event Timeline