@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Aviv Eyal and committed by
epriestley
361e49dd cd080b09

+21 -24
+21 -24
scripts/symbols/import_project_symbols.php
··· 106 106 107 107 } 108 108 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 + 109 124 $no_purge = $args->getArg('no-purge'); 110 125 $symbols = array(); 111 126 foreach ($input as $key => $line) { ··· 137 152 $line_number = $matches['line']; 138 153 $path = $matches['path']; 139 154 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 - } 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); 157 160 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 - } 163 - 164 - if (!strlen($path) || $path[0] != 0) { 161 + if (!strlen($path) || $path[0] != '/') { 165 162 throw new Exception( 166 163 "Path '{$path}' defined on line #{$line_no} is invalid. Paths should ". 167 164 "begin with '/' and specify a path from the root of the project, like ".