|
15 | 15 |
|
16 | 16 | import java.util.Map; |
17 | 17 | import java.util.Set; |
18 | | -import java.util.regex.Matcher; |
19 | | -import java.util.regex.Pattern; |
20 | 18 |
|
21 | 19 | public class PDETextHelper { |
22 | 20 |
|
@@ -283,13 +281,49 @@ private static boolean isValidTagAttributeList(String text) { |
283 | 281 | // " att1="value1" att2="value2" |
284 | 282 | // " att1="value1" att2="value2 /" |
285 | 283 | // " att1="value1" |
| 284 | + while (!text.isBlank()) { |
| 285 | + int idx = text.indexOf('='); |
| 286 | + if (idx < 0) { |
| 287 | + return text.trim().equals("/"); //$NON-NLS-1$ |
| 288 | + } |
| 289 | + String key = text.substring(0, idx).trim(); |
| 290 | + if (!isValidAttributeKey(key)) { |
| 291 | + return false; |
| 292 | + } |
| 293 | + String remaining = text.substring(idx + 1).trim(); |
| 294 | + if (!remaining.startsWith("\"")) { //$NON-NLS-1$ |
| 295 | + return false; |
| 296 | + } |
| 297 | + int end = remaining.indexOf('"', 1); |
| 298 | + if (end < 0) { |
| 299 | + return false; |
| 300 | + } |
| 301 | + text = remaining.substring(end + 1); |
| 302 | + } |
| 303 | + return true; |
| 304 | + } |
| 305 | + |
| 306 | + private static boolean isValidAttributeKey(String key) { |
| 307 | + if (key.isEmpty()) { |
| 308 | + return false; |
| 309 | + } |
| 310 | + int length = key.length(); |
| 311 | + for (int i = 0; i < length; i++) { |
| 312 | + char c = key.charAt(i); |
| 313 | + if (!isValidAttributeKeyChar(c)) { |
| 314 | + return false; |
| 315 | + } |
| 316 | + } |
| 317 | + return true; |
| 318 | + } |
286 | 319 |
|
287 | | - // space attributeName space = space "attributeValue" space / |
288 | | - String patternString = "^([\\s]+[A-Za-z0-9_:\\-\\.]+[\\s]?=[\\s]?\".+?\")*[\\s]*[/]?$"; //$NON-NLS-1$ |
289 | | - Pattern pattern = Pattern.compile(patternString); |
290 | | - Matcher matcher = pattern.matcher(text); |
291 | | - // Determine whether the given attribute list matches the pattern |
292 | | - return matcher.find(); |
| 320 | + private static boolean isValidAttributeKeyChar(char c) { |
| 321 | + return (c >= 'A' && c <= 'Z') || // |
| 322 | + (c >= 'a' && c <= 'z') || // |
| 323 | + (c >= '0' && c <= '9') || // |
| 324 | + c == '_' || // |
| 325 | + c == '-' || // |
| 326 | + c == ':'; |
293 | 327 | } |
294 | 328 |
|
295 | 329 | private static String getTagName(String buffer) { |
|
0 commit comments