Changeset 1447


Ignore:
Timestamp:
Dec 17, 2002, 11:32:26 AM (18 years ago)
Author:
landonf (Landon Fuller)
Message:

Added regex special character escaping when searching for a user supplied string literal

Location:
branches/landonf-1_0/base/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/landonf-1_0/base/src/port/port.tcl

    r1434 r1447  
    160160    puts stderr "$argv0: $args"
    161161    exit
     162}
     163
     164# Escape regex special characters
     165proc regex_escape {string} {
     166    puts $string
     167    regsub -all "(\\(){1}|(\\)){1}|(\\{1}){1}|(\\+){1}|(\\{1}){1}|(\\{){1}|(\\}){1}|(\\^){1}|(\\$){1}|(\\.){1}|(\\\\){1}" $string "\\\\&" escaped
     168    return $escaped
    162169}
    163170
     
    271278        set target $action
    272279        if {[info exists portname]} {
    273             if {[catch {set res [dportsearch ^$portname\$]} result]} {
    274                 puts $result
     280            set res [dportsearch ^[regex_escape $portname]\$]
     281            if {[catch {set res [dportsearch ^[regex_escape $portname]\$]} result]} {
     282                puts "port search failed: $result"
    275283                exit 1
    276284            }
  • branches/landonf-1_0/base/src/port1.0/portutil.tcl

    r1376 r1447  
    10851085        set options(workpath) ${newworkpath}
    10861086    }
    1087        
    1088     set res [dportsearch ^$portname\$]
     1087        # Escape regex special characters
     1088        regsub -all "(\\(){1}|(\\)){1}|(\\{1}){1}|(\\+){1}|(\\{1}){1}|(\\{){1}|(\\}){1}|(\\^){1}|(\\$){1}|(\\.){1}|(\\\\){1}" $portname "\\\\&" searchstring
     1089
     1090    set res [dportsearch ^$searchstring\$]
    10891091    if {[llength $res] < 2} {
    10901092        ui_error "Portfile $portname not found"
    10911093        return -1
    10921094    }
     1095
    10931096    array set portinfo [lindex $res 1]
    10941097    set porturl $portinfo(porturl)
Note: See TracChangeset for help on using the changeset viewer.