Changeset 19443 in josm


Ignore:
Timestamp:
2025-10-09T11:03:09+02:00 (5 weeks ago)
Author:
GerdP
Message:

fix #24480: 19437 introduced client side tag checking impacting private server.

  • implement boolean preference upload.check-maxlength-value which allows to disable the maxlength check of tag values on upload
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/upload/ApiPreconditionCheckerHook.java

    r19437 r19443  
    1414import org.openstreetmap.josm.data.osm.Tagged;
    1515import org.openstreetmap.josm.data.osm.Way;
     16import org.openstreetmap.josm.data.preferences.AbstractProperty;
     17import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1618import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    1719import org.openstreetmap.josm.gui.MainApplication;
     
    3032 */
    3133public class ApiPreconditionCheckerHook implements UploadHook {
     34    static AbstractProperty<Boolean> PREF_LENGTH_CHECK = new BooleanProperty("upload.check-maxlength-value", true).cached();
    3235
    3336    @Override
     
    6265    private static boolean checkMaxNodes(Collection<OsmPrimitive> primitives, long maxNodes) {
    6366        for (OsmPrimitive osmPrimitive : primitives) {
    64             for (Map.Entry<String, String> entry: osmPrimitive.getKeys().entrySet()) {
    65                 String key = entry.getKey();
    66                 String value = entry.getValue();
    67                 if (!Utils.checkCodePointCount(value, Tagged.MAX_TAG_LENGTH)) {
    68                     if (osmPrimitive.isDeleted()) {
    69                         // if OsmPrimitive is going to be deleted we automatically shorten the value
    70                         Logging.warn(
    71                                 tr("Automatically truncating value of tag ''{0}'' on deleted object {1}",
    72                                         key,
    73                                         Long.toString(osmPrimitive.getId())
    74                                 )
    75                         );
    76                         osmPrimitive.put(key, Utils.shortenString(value, Tagged.MAX_TAG_LENGTH));
    77                         continue;
    78                     }
    79                     JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    80                             tr("Length of value for tag ''{0}'' on object {1} exceeds the max. allowed length {2}. Values length is {3}.",
    81                                     key, Long.toString(osmPrimitive.getId()), Tagged.MAX_TAG_LENGTH, Utils.getCodePointCount(value)
    82                             ),
    83                             tr("Precondition violation"),
    84                             JOptionPane.ERROR_MESSAGE
    85                     );
    86                     MainApplication.getLayerManager().getEditDataSet().setSelected(Collections.singleton(osmPrimitive));
    87                     return false;
    88                 }
     67            if (Boolean.TRUE.equals(PREF_LENGTH_CHECK.get()) && !valueLengthCheck(osmPrimitive)) {
     68                return false;
    8969            }
    9070
     
    10787        return true;
    10888    }
     89
     90    /**
     91     * Check that the tag values of a primitive are not too long.
     92     * @param osmPrimitive the primitive to check
     93     * @return false if any tag value of the primitive is too long, true else
     94     */
     95    private static boolean valueLengthCheck(OsmPrimitive osmPrimitive) {
     96        for (Map.Entry<String, String> entry: osmPrimitive.getKeys().entrySet()) {
     97            String key = entry.getKey();
     98            String value = entry.getValue();
     99            if (!Utils.checkCodePointCount(value, Tagged.MAX_TAG_LENGTH)) {
     100                if (osmPrimitive.isDeleted()) {
     101                    // if OsmPrimitive is going to be deleted we automatically shorten the value
     102                    Logging.warn(
     103                            tr("Automatically truncating value of tag ''{0}'' on deleted object {1}",
     104                                    key,
     105                                    Long.toString(osmPrimitive.getId())
     106                            )
     107                    );
     108                    osmPrimitive.put(key, Utils.shortenString(value, Tagged.MAX_TAG_LENGTH));
     109                    continue;
     110                }
     111                JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
     112                        tr("Length of value for tag ''{0}'' on object {1} exceeds the max. allowed length {2}. Values length is {3}.",
     113                                key, Long.toString(osmPrimitive.getId()), Tagged.MAX_TAG_LENGTH, Utils.getCodePointCount(value)
     114                        ),
     115                        tr("Precondition violation"),
     116                        JOptionPane.ERROR_MESSAGE
     117                );
     118                MainApplication.getLayerManager().getEditDataSet().setSelected(Collections.singleton(osmPrimitive));
     119                return false;
     120            }
     121        }
     122        return true;
     123    }
    109124}
Note: See TracChangeset for help on using the changeset viewer.