Mercurial > urweb
comparison src/c/urweb.c @ 925:552c989c1601
Change string URLification to avoid using the empty string, which confuses Apache no2slash()
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 12 Sep 2009 09:31:50 -0400 |
parents | d6a71f19a3d8 |
children | d136bc34e4ca |
comparison
equal
deleted
inserted
replaced
924:803342eb2dc0 | 925:552c989c1601 |
---|---|
1477 } | 1477 } |
1478 | 1478 |
1479 char *uw_Basis_urlifyString(uw_context ctx, uw_Basis_string s) { | 1479 char *uw_Basis_urlifyString(uw_context ctx, uw_Basis_string s) { |
1480 char *r, *p; | 1480 char *r, *p; |
1481 | 1481 |
1482 uw_check_heap(ctx, strlen(s) * 3 + 1); | 1482 if (s[0] == '\0') |
1483 | 1483 return "_"; |
1484 for (r = p = ctx->heap.front; *s; s++) { | 1484 |
1485 uw_check_heap(ctx, strlen(s) * 3 + 1 + !!(s[0] == '_')); | |
1486 | |
1487 r = p = ctx->heap.front; | |
1488 if (s[0] == '_') | |
1489 *p++ = '_'; | |
1490 | |
1491 for (; *s; s++) { | |
1485 char c = *s; | 1492 char c = *s; |
1486 | 1493 |
1487 if (c == ' ') | 1494 if (c == ' ') |
1488 *p++ = '+'; | 1495 *p++ = '+'; |
1489 else if (isalnum(c)) | 1496 else if (isalnum(c)) |
1545 uw_Basis_string uw_Basis_urlifyTime(uw_context ctx, uw_Basis_time t) { | 1552 uw_Basis_string uw_Basis_urlifyTime(uw_context ctx, uw_Basis_time t) { |
1546 return uw_Basis_urlifyInt(ctx, t); | 1553 return uw_Basis_urlifyInt(ctx, t); |
1547 } | 1554 } |
1548 | 1555 |
1549 uw_unit uw_Basis_urlifyString_w(uw_context ctx, uw_Basis_string s) { | 1556 uw_unit uw_Basis_urlifyString_w(uw_context ctx, uw_Basis_string s) { |
1550 uw_check(ctx, strlen(s) * 3); | 1557 if (s[0] == '\0') { |
1558 uw_check(ctx, 1); | |
1559 uw_writec_unsafe(ctx, '_'); | |
1560 return uw_unit_v; | |
1561 } | |
1562 | |
1563 uw_check(ctx, strlen(s) * 3 + !!(s[0] == '_')); | |
1564 | |
1565 if (s[0] == '_') | |
1566 uw_writec_unsafe(ctx, '_'); | |
1551 | 1567 |
1552 for (; *s; s++) { | 1568 for (; *s; s++) { |
1553 char c = *s; | 1569 char c = *s; |
1554 | 1570 |
1555 if (c == ' ') | 1571 if (c == ' ') |
1609 } | 1625 } |
1610 | 1626 |
1611 static uw_Basis_string uw_unurlifyString_to(uw_context ctx, char *r, char *s) { | 1627 static uw_Basis_string uw_unurlifyString_to(uw_context ctx, char *r, char *s) { |
1612 char *s1, *s2; | 1628 char *s1, *s2; |
1613 int n; | 1629 int n; |
1630 | |
1631 if (*s2 == '_') | |
1632 ++s2; | |
1633 else if (s2[0] == '%' && s2[1] == '5' && (s2[2] == 'f' || s2[2] == 'F')) | |
1634 s2 += 3; | |
1614 | 1635 |
1615 for (s1 = r, s2 = s; *s2; ++s1, ++s2) { | 1636 for (s1 = r, s2 = s; *s2; ++s1, ++s2) { |
1616 char c = *s2; | 1637 char c = *s2; |
1617 | 1638 |
1618 switch (c) { | 1639 switch (c) { |