Changeset 17497 in josm for trunk


Ignore:
Timestamp:
2021-02-20T20:52:51+01:00 (3 years ago)
Author:
Don-vip
Message:

fix #20498 - make sure fixChangeKey does not overwrite existing tag

File:
1 edited

Legend:

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

    r17011 r17497  
    106106         * @param p OSM primitive
    107107         * @param matchingSelector  matching selector
    108          * @return fix command
     108         * @return fix command, or {@code null} if if cannot be created
    109109         */
    110110        Command createCommand(OsmPrimitive p, Selector matchingSelector);
     
    182182
    183183        /**
    184          * Creates a fixing command which executes a {@link ChangePropertyKeyCommand} on the specified keys.
     184         * Creates a fixing command which executes a {@link ChangePropertyKeyCommand} on the specified keys
     185         * if {@code p} does not already have {@code newKey}
    185186         * @param oldKey old key
    186187         * @param newKey new key
    187          * @return created fix command
     188         * @return created fix command, or {@code null}
    188189         */
    189190        static FixCommand fixChangeKey(final String oldKey, final String newKey) {
     
    191192                @Override
    192193                public Command createCommand(OsmPrimitive p, Selector matchingSelector) {
    193                     return new ChangePropertyKeyCommand(p,
     194                    return p.hasKey(newKey) ? null : new ChangePropertyKeyCommand(p,
    194195                            TagCheck.insertArguments(matchingSelector, oldKey, p),
    195196                            TagCheck.insertArguments(matchingSelector, newKey, p));
     
    465466                Collection<Command> cmds = fixCommands.stream()
    466467                        .map(fixCommand -> fixCommand.createCommand(p, matchingSelector))
     468                        .filter(Objects::nonNull)
    467469                        .collect(Collectors.toList());
    468470                if (deletion && !p.isDeleted()) {
    469471                    cmds.add(new DeleteCommand(p));
    470472                }
    471                 return new SequenceCommand(tr("Fix of {0}", getDescriptionForMatchingSelector(p, matchingSelector)), cmds);
     473                return cmds.isEmpty() ? null
     474                        : new SequenceCommand(tr("Fix of {0}", getDescriptionForMatchingSelector(p, matchingSelector)), cmds);
    472475            } catch (IllegalArgumentException e) {
    473476                Logging.error(e);
Note: See TracChangeset for help on using the changeset viewer.