MCPcopy Create free account
hub / github.com/davidgiven/luje / validate

Method validate

lib/java/net/URIEncoderDecoder.java:51–80  ·  view source on GitHub ↗

Validate a string by checking if it contains any characters other than: 1. letters ('a'..'z', 'A'..'Z') 2. numbers ('0'..'9') 3. characters in the legalset parameter 4. others (unicode characters that are not in US-ASCII set, and are not ISO Control or are not ISO Space characters) called from {

(String s, String legal)

Source from the content-addressed store, hash-verified

49 * s
50 */
51 static void validate(String s, String legal) throws URISyntaxException {
52 for (int i = 0; i < s.length();) {
53 char ch = s.charAt(i);
54 if (ch == '%') {
55 do {
56 if (i + 2 >= s.length()) {
57 throw new URISyntaxException(s, Messages.getString("luni.7D"), //$NON-NLS-1$
58 i);
59 }
60 int d1 = Character.digit(s.charAt(i + 1), 16);
61 int d2 = Character.digit(s.charAt(i + 2), 16);
62 if (d1 == -1 || d2 == -1) {
63 throw new URISyntaxException(s, Messages.getString("luni.7E", //$NON-NLS-1$
64 s.substring(i, i + 3)), i);
65 }
66
67 i += 3;
68 } while (i < s.length() && s.charAt(i) == '%');
69
70 continue;
71 }
72 if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
73 || (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1 || (ch > 127
74 && !Character.isSpaceChar(ch) && !Character
75 .isISOControl(ch)))) {
76 throw new URISyntaxException(s, Messages.getString("luni.7F"), i); //$NON-NLS-1$
77 }
78 i++;
79 }
80 }
81
82 static void validateSimple(String s, String legal)
83 throws URISyntaxException {

Callers 5

validateSspMethod · 0.95
validateAuthorityMethod · 0.95
validatePathMethod · 0.95
validateQueryMethod · 0.95
validateFragmentMethod · 0.95

Calls 8

getStringMethod · 0.95
digitMethod · 0.95
isSpaceCharMethod · 0.95
isISOControlMethod · 0.95
lengthMethod · 0.65
charAtMethod · 0.65
indexOfMethod · 0.65
substringMethod · 0.45

Tested by

no test coverage detected