[34667] trunk/base/src/port1.0

raimue at macports.org raimue at macports.org
Sat Mar 1 15:54:45 PST 2008


Revision: 34667
          http://trac.macosforge.org/projects/macports/changeset/34667
Author:   raimue at macports.org
Date:     2008-03-01 15:54:44 -0800 (Sat, 01 Mar 2008)

Log Message:
-----------
port1.0/portutil.tcl:
 * Add a new function quotemeta, which can be used to escape strings for safe use inside regular expressions

port1.0/portlivecheck.tcl:
 * Escape any variable used inside ${livecheck.regex} using this new function

Closes #14067

Modified Paths:
--------------
    trunk/base/src/port1.0/portlivecheck.tcl
    trunk/base/src/port1.0/portutil.tcl

Modified: trunk/base/src/port1.0/portlivecheck.tcl
===================================================================
--- trunk/base/src/port1.0/portlivecheck.tcl	2008-03-01 23:09:32 UTC (rev 34666)
+++ trunk/base/src/port1.0/portlivecheck.tcl	2008-03-01 23:54:44 UTC (rev 34667)
@@ -124,7 +124,7 @@
                 set livecheck.distname ${livecheck.name}
             }
             if {${livecheck.regex} eq ""} {
-                set livecheck.regex "<title>${livecheck.distname} (.*) released.*</title>"
+                set livecheck.regex "<title>[quotemeta ${livecheck.distname}] (.*) released.*</title>"
             }
             set livecheck.check "regex"
         }
@@ -136,7 +136,7 @@
                 set livecheck.distname [regsub ***=${livecheck.version} [file tail [lindex ${distfiles} 0]] (.*)]
             }
             if {${livecheck.regex} eq ""} {
-                set livecheck.regex {<a href="http://${livecheck.name}.googlecode.com/files/${livecheck.distname}"}
+                set livecheck.regex "<a href=\"http://[quotemeta ${livecheck.name}].googlecode.com/files/[quotemeta ${livecheck.distname}]\""
             }
             set livecheck.check "regex"
         }
@@ -148,7 +148,7 @@
                 set livecheck.distname ${livecheck.name}
             }
             if {${livecheck.regex} eq ""} {
-                set livecheck.regex {${livecheck.distname}-(\\d+(?:\\.\\d+)*)}
+                set livecheck.regex "[quotemeta ${livecheck.distname}]-(\\\\d+(?:\\\\.\\\\d+)*)"
             }
             set livecheck.check "regex"
         }
@@ -169,7 +169,7 @@
                 # let's extract the version from the file.
                 set chan [open $tempfile "r"]
                 set updated -1
-                set the_re [subst -nocommands -nobackslashes [join ${livecheck.regex}]]
+                set the_re [join ${livecheck.regex}]
                 ui_debug "The regex is >$the_re<"
                 if {${livecheck.check} == "regexm"} {
                     set data [read $chan]

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2008-03-01 23:09:32 UTC (rev 34666)
+++ trunk/base/src/port1.0/portutil.tcl	2008-03-01 23:54:44 UTC (rev 34667)
@@ -2049,3 +2049,13 @@
     }
 }
 
+##
+# Escape a string for safe use in regular expressions
+#
+# @param str the string to be quoted
+# @return the escaped string
+proc quotemeta {str} {
+    regsub -all {(\W)} $str {\\\1} str
+    return $str
+}
+

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080301/317bee52/attachment.html 


More information about the macports-changes mailing list