Ignore:
Timestamp:
2020-11-23T19:59:45+01:00 (3 years ago)
Author:
GerdP
Message:

fix #20037: Overpass query wizard generates wrong query with "*=value"

  • remove obsolete getInstance()
  • fix bug and add unit test
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java

    r16358 r17336  
    2626public final class SearchCompilerQueryWizard {
    2727
    28     private static final SearchCompilerQueryWizard instance = new SearchCompilerQueryWizard();
    29 
    30     /**
    31      * Replies the unique instance of this class.
    32      *
    33      * @return the unique instance of this class
    34      */
    35     public static SearchCompilerQueryWizard getInstance() {
    36         return instance;
    37     }
    38 
    3928    private SearchCompilerQueryWizard() {
    4029        // private constructor for utility class
     
    4736     * @throws UncheckedParseException when the parsing fails
    4837     */
    49     public String constructQuery(final String search) {
     38    public static String constructQuery(final String search) {
    5039        try {
    5140            Matcher matcher = Pattern.compile("\\s+GLOBAL\\s*$", Pattern.CASE_INSENSITIVE).matcher(search);
     
    7463                }
    7564            }
    76            
     65
    7766            final Match match = SearchCompiler.compile(search);
    7867            return constructQuery(match, "[bbox:{{bbox}}];", "");
     
    8271    }
    8372
    84     private String constructQuery(final Match match, final String bounds, final String queryLineSuffix) {
     73    private static String constructQuery(final Match match, final String bounds, final String queryLineSuffix) {
    8574        final List<Match> normalized = normalizeToDNF(match);
    8675        final List<String> queryLines = new ArrayList<>();
     
    136125                case EXACT:
    137126                    return "[" + quote(key) + (negated ? "!=" : "=") + quote(value) + "]";
     127                case ANY_KEY: // *=value
     128                    // fall through
    138129                case EXACT_REGEXP:
    139130                    final Matcher matcher = Pattern.compile("/(?<regex>.*)/(?<flags>i)?").matcher(value);
     
    141132                            ? quote(matcher.group("regex")) + Optional.ofNullable(matcher.group("flags")).map(f -> "," + f).orElse("")
    142133                            : quote(value);
     134                    if (mode == SearchCompiler.ExactKeyValue.Mode.ANY_KEY)
     135                        return "[~\"^.*$\"" + (negated ? "!~" : "~") + valueQuery + "]";
    143136                    return "[" + quote(key) + (negated ? "!~" : "~") + valueQuery + "]";
    144137                case MISSING_KEY:
Note: See TracChangeset for help on using the changeset viewer.