@@ -106,6 +106,21 @@ function commit_symbols ($syms, $project, $no_purge) {
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,31 +152,13 @@ function commit_symbols ($syms, $project, $no_purge) {
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
- }
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 );
163
160
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 " .
0 commit comments