Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 1a2c2b5249c469f72384f24449aabb7c0cfa8d86
Ticket: a4a7f2abd376b2806073d2865f07b7d910b04574
Tcl [string match] and [glob] are exponential complexity for bad patterns, could be linear
User & Date: aspect on 2017-05-02 11:12:40
Changes

  1. icomment:
    Trying to simplify Tcl_StringCaseMatch so I can attack this, a bunch of strange edge cases come up:
    
    % string match {[a} a
    1
    % string match {[a-} a
    0
    % string match {[a-z} a
    1
    % string match {[a-z} b
    1
    % string match {[a-]} a
    1
    % string match {[a-]} b
    0
    % string match {[a-]} -
    0
    % string match {[-a]} a
    1
    % string match {[-a]} b
    0
    % string match {[-a]} -
    1
    
    Further, any pattern ending with an odd number of backslashes will never match.
    
    There are three special cases to consider:
    
    #1 - malformed pattern: ends with single \
    #2 - malformed pattern: unclosed [ sequence
    #3 - [a-] (and [-a])
    
    I think #3 should match exactly "a" and "-", as [-a] does presently.  glob(3) agrees.  The wording of string(n) implies this is what will happen.
    
    for #1, #2 there are three arguments:
    
     a: malformed patterns should be an error.
    
     b: agree with glob(3) and treat them as literals.
    
     c: malformed patterns match nothing.
    
    Since Tcl_StringMatch has no way to report errors, (a) is off the table.  I lean slightly to option (c) because it keeps the code simpler, and is closest to what Tcl_StringMatch seems to want to do.
    
  2. login: "aspect"
  3. mimetype: "text/plain"