Changeset 13489 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2018-03-03T20:33:09+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #16044 - Autofix invalid URL with the wrong type of slashes

Location:
trunk/src/org/openstreetmap/josm/data/validation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r13453 r13489  
    191191         * Sets a supplier to obtain a command to fix the error.
    192192         *
    193          * @param fixingCommand the fix supplier
     193         * @param fixingCommand the fix supplier. Can be null
    194194         * @return {@code this}
    195195         */
  • trunk/src/org/openstreetmap/josm/data/validation/tests/InternetTags.java

    r12539 r13489  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
     7import java.util.function.Supplier;
     8
     9import org.openstreetmap.josm.command.ChangePropertyCommand;
     10import org.openstreetmap.josm.command.Command;
    711import org.openstreetmap.josm.data.osm.Node;
    812import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    97101        String value = v != null ? v : p.get(k);
    98102        if (!validator.isValid(value)) {
     103            Supplier<Command> fix = null;
    99104            String errMsg = validator.getErrorMessage();
    100             // Special treatment to allow URLs without protocol. See UrlValidator#isValid
    101105            if (tr("URL contains an invalid protocol: {0}", (String) null).equals(errMsg)) {
     106                // Special treatment to allow URLs without protocol. See UrlValidator#isValid
    102107                String proto = validator instanceof EmailValidator ? "mailto://" : "http://";
    103108                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("\\\\", "/"));
    104114            }
    105115            error = TestError.builder(this, Severity.WARNING, code)
    106116                    .message(validator.getValidatorName(), marktr("''{0}'': {1}"), k, errMsg)
    107117                    .primitives(p)
     118                    .fix(fix)
    108119                    .build();
    109120        }
Note: See TracChangeset for help on using the changeset viewer.