1
0
mirror of https://github.com/golang/go synced 2024-11-20 05:44:44 -07:00

gc: package paths in symbol names: don't escape periods before last slash, always escape >=0x7f.

R=rsc
CC=golang-dev
https://golang.org/cl/5323071
This commit is contained in:
Luuk van Dijk 2011-11-02 22:33:15 +01:00
parent 965845a86d
commit 33f1d47b38

View File

@ -2911,21 +2911,29 @@ ngotype(Node *n)
} }
/* /*
* Convert raw string to the prefix that will be used in the symbol table. * Convert raw string to the prefix that will be used in the symbol
* Invalid bytes turn into %xx. Right now the only bytes that need * table. All control characters, space, '%' and '"', as well as
* escaping are %, ., and ", but we escape all control characters too. * 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* static char*
pathtoprefix(char *s) pathtoprefix(char *s)
{ {
static char hex[] = "0123456789abcdef"; static char hex[] = "0123456789abcdef";
char *p, *r, *w; char *p, *r, *w, *l;
int n; 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 // check for chars that need escaping
n = 0; n = 0;
for(r=s; *r; r++) for(r=s; *r; r++)
if(*r <= ' ' || *r == '.' || *r == '%' || *r == '"') if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f)
n++; n++;
// quick exit // quick exit
@ -2935,7 +2943,7 @@ pathtoprefix(char *s)
// escape // escape
p = mal((r-s)+1+2*n); p = mal((r-s)+1+2*n);
for(r=s, w=p; *r; r++) { for(r=s, w=p; *r; r++) {
if(*r <= ' ' || *r == '.' || *r == '%' || *r == '"') { if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f) {
*w++ = '%'; *w++ = '%';
*w++ = hex[(*r>>4)&0xF]; *w++ = hex[(*r>>4)&0xF];
*w++ = hex[*r&0xF]; *w++ = hex[*r&0xF];