Changeset 5534


Ignore:
Timestamp:
Dec 20, 2010, 9:17:46 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1565: Command line options for the external program executor that contain quotes are not handled correctly

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/StringUtil.java

    r5519 r5534  
    182182    regular expression, optionally ignoring matches that are inside
    183183    quotes.
     184   
    184185    @param s The string to tokenize
    185186    @param regexp The regular expression for matching split sites
     187    @param notInsideQuotes If TRUE, the regexp is not matched inside quotes
    186188    @return An array with the elements of the array
    187189    @since 2.15
    188190  */
    189   public static final String[] tokenize(String s, String regexp, boolean notInsideQoutes)
     191  public static final String[] tokenize(String s, String regexp, boolean notInsideQuotes)
     192  {
     193    return tokenize(s, regexp, notInsideQuotes, false);
     194  }
     195
     196  /**
     197    Tokenize a string by splitting it at positions matching the
     198    regular expression. Matches that are inside quotes can optionally
     199    be ignored. Elements with quotes can optionally have the quotes
     200    removed.
     201   
     202    @param s The string to tokenize
     203    @param regexp The regular expression for matching split sites
     204    @param notInsideQuotes If TRUE, the regexp is not matched inside quotes
     205    @param removeQuotes If TRUE, remove quotes from all elements before returning the
     206      result
     207     
     208    @return An array with the elements of the array
     209    @since 2.17
     210  */
     211  public static final String[] tokenize(String s, String regexp, boolean notInsideQuotes, boolean removeQuotes)
    190212  {
    191213    String[] result = null;
    192214    if (s != null && regexp != null)
    193215    {
    194       if (notInsideQoutes) regexp += "(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";
     216      if (notInsideQuotes) regexp += "(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";
    195217      result = s.split(regexp);
     218      if (removeQuotes)
     219      {
     220        for (int i = 0; i < result.length; ++i)
     221        {
     222          String t = result[i];
     223          if (t != null && t.startsWith("\"") && t.endsWith("\""))
     224          {
     225            result[i] = t.substring(1, t.length()-1);
     226          }
     227        }
     228      }
    196229    }
    197230    return result;
    198231  }
    199  
     232
    200233
    201234  /**
  • trunk/src/plugins/core/net/sf/basedb/plugins/executor/ExternalProgramExecutor.java

    r5481 r5534  
    721721    if (cmdLine != null)
    722722    {
    723       // Split on whitespace but not inside quotes
    724       cmds.addAll(Arrays.asList(StringUtil.tokenize(cmdLine, "\\s+", true)));
     723      // Split on whitespace but not inside quotes; quotes are removed
     724      String[] options = StringUtil.tokenize(cmdLine, "\\s+", true, true);
     725      if (options != null)
     726      {
     727        cmds.addAll(Arrays.asList(options));
     728      }
    725729    }
    726730    builder.command(cmds);
Note: See TracChangeset for help on using the changeset viewer.