]> Cypherpunks repositories - gostls13.git/commitdiff
gc: package paths in symbol names: don't escape periods before last slash, always...
authorLuuk van Dijk <lvd@golang.org>
Wed, 2 Nov 2011 21:33:15 +0000 (22:33 +0100)
committerLuuk van Dijk <lvd@golang.org>
Wed, 2 Nov 2011 21:33:15 +0000 (22:33 +0100)
R=rsc
CC=golang-dev
https://golang.org/cl/5323071

src/cmd/gc/subr.c

index dc1d3146381790790a813196e1f745093dfb43cc..b8cdd27ad4a5a4ff5eb548566a8dd3fd7ca24ca8 100644 (file)
@@ -2911,21 +2911,29 @@ ngotype(Node *n)
 }
 
 /*
- * Convert raw string to the prefix that will be used in the symbol table.
- * Invalid bytes turn into %xx.  Right now the only bytes that need
- * escaping are %, ., and ", but we escape all control characters too.
+ * Convert raw string to the prefix that will be used in the symbol
+ * table.  All control characters, space, '%' and '"', as well as
+ * non-7-bit clean bytes turn into %xx.  The period needs escaping
+ * only in the last segment of the path, and it makes for happier
+ * users if we escape that as little as possible.
  */
 static char*
 pathtoprefix(char *s)
 {
        static char hex[] = "0123456789abcdef";
-       char *p, *r, *w;
+       char *p, *r, *w, *l;
        int n;
 
+       // find first character past the last slash, if any.
+       l = s;
+       for(r=s; *r; r++)
+               if(*r == '/')
+                       l = r+1;
+
        // check for chars that need escaping
        n = 0;
        for(r=s; *r; r++)
-               if(*r <= ' ' || *r == '.' || *r == '%' || *r == '"')
+               if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f)
                        n++;
 
        // quick exit
@@ -2935,7 +2943,7 @@ pathtoprefix(char *s)
        // escape
        p = mal((r-s)+1+2*n);
        for(r=s, w=p; *r; r++) {
-               if(*r <= ' ' || *r == '.' || *r == '%' || *r == '"') {
+               if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f) {
                        *w++ = '%';
                        *w++ = hex[(*r>>4)&0xF];
                        *w++ = hex[*r&0xF];