Changeset 14803 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-02-24T20:25:48+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/InternetTags.java
r13489 r14803 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.util.ArrayList; 8 import java.util.List; 7 9 import java.util.function.Supplier; 8 10 … … 65 67 for (String i : keys) { 66 68 if (i.equals(k)) { 67 TestError error = validateTag(p, k, validator, code); 68 if (error != null) { 69 errors.add(error); 70 } 71 break; 69 return errors.addAll(validateTag(p, k, validator, code)); 72 70 } 73 71 } … … 83 81 * @return The error if the validation fails, {@code null} otherwise 84 82 * @since 7824 83 * @since 14803 (return type) 85 84 */ 86 public TestErrorvalidateTag(OsmPrimitive p, String k, AbstractValidator validator, int code) {85 public List<TestError> validateTag(OsmPrimitive p, String k, AbstractValidator validator, int code) { 87 86 return doValidateTag(p, k, null, validator, code); 88 87 } … … 97 96 * @return The error if the validation fails, {@code null} otherwise 98 97 */ 99 private TestError doValidateTag(OsmPrimitive p, String k, String v, AbstractValidator validator, int code) { 100 TestError error = null; 101 String value = v != null ? v : p.get(k); 102 if (!validator.isValid(value)) { 103 Supplier<Command> fix = null; 104 String errMsg = validator.getErrorMessage(); 105 if (tr("URL contains an invalid protocol: {0}", (String) null).equals(errMsg)) { 106 // Special treatment to allow URLs without protocol. See UrlValidator#isValid 107 String proto = validator instanceof EmailValidator ? "mailto://" : "http://"; 108 return doValidateTag(p, k, proto+value, validator, code); 109 } else if (tr("URL contains an invalid authority: {0}", (String) null).equals(errMsg) 110 && value.contains("\\") && validator.isValid(value.replaceAll("\\\\", "/"))) { 111 // Special treatment to autofix URLs with backslashes. See UrlValidator#isValid 112 errMsg = tr("URL contains backslashes instead of slashes"); 113 fix = () -> new ChangePropertyCommand(p, k, value.replaceAll("\\\\", "/")); 98 private List<TestError> doValidateTag(OsmPrimitive p, String k, String v, AbstractValidator validator, int code) { 99 List<TestError> errors = new ArrayList<>(); 100 String values = v != null ? v : p.get(k); 101 for (String value : values.split(";")) { 102 if (!validator.isValid(value)) { 103 Supplier<Command> fix = null; 104 String errMsg = validator.getErrorMessage(); 105 if (tr("URL contains an invalid protocol: {0}", (String) null).equals(errMsg)) { 106 // Special treatment to allow URLs without protocol. See UrlValidator#isValid 107 String proto = validator instanceof EmailValidator ? "mailto://" : "http://"; 108 return doValidateTag(p, k, proto+value, validator, code); 109 } else if (tr("URL contains an invalid authority: {0}", (String) null).equals(errMsg) 110 && value.contains("\\") && validator.isValid(value.replaceAll("\\\\", "/"))) { 111 // Special treatment to autofix URLs with backslashes. See UrlValidator#isValid 112 errMsg = tr("URL contains backslashes instead of slashes"); 113 fix = () -> new ChangePropertyCommand(p, k, value.replaceAll("\\\\", "/")); 114 } 115 errors.add(TestError.builder(this, Severity.WARNING, code) 116 .message(validator.getValidatorName(), marktr("''{0}'': {1}"), k, errMsg) 117 .primitives(p) 118 .fix(fix) 119 .build()); 114 120 } 115 error = TestError.builder(this, Severity.WARNING, code)116 .message(validator.getValidatorName(), marktr("''{0}'': {1}"), k, errMsg)117 .primitives(p)118 .fix(fix)119 .build();120 121 } 121 return error ;122 return errors; 122 123 } 123 124
Note:
See TracChangeset
for help on using the changeset viewer.