diff options
Diffstat (limited to 'src/gmutil.c')
-rw-r--r-- | src/gmutil.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gmutil.c b/src/gmutil.c index 23f5142f..d8f58a10 100644 --- a/src/gmutil.c +++ b/src/gmutil.c | |||
@@ -561,13 +561,22 @@ const char *mediaType_Path(const iString *path) { | |||
561 | return "application/octet-stream"; | 561 | return "application/octet-stream"; |
562 | } | 562 | } |
563 | 563 | ||
564 | void urlEncodeSpaces_String(iString *d) { | 564 | static void replaceAllChars_String_(iString *d, char c, const char *replacement) { |
565 | const char cstr[2] = { c, 0 }; | ||
566 | const size_t repLen = strlen(replacement); | ||
567 | size_t pos = 0; | ||
565 | for (;;) { | 568 | for (;;) { |
566 | const size_t pos = indexOfCStr_String(d, " "); | 569 | pos = indexOfCStrFrom_String(d, cstr, pos); |
567 | if (pos == iInvalidPos) break; | 570 | if (pos == iInvalidPos) break; |
568 | remove_Block(&d->chars, pos, 1); | 571 | remove_Block(&d->chars, pos, 1); |
569 | insertData_Block(&d->chars, pos, "%20", 3); | 572 | insertData_Block(&d->chars, pos, replacement, repLen); |
570 | } | 573 | pos += repLen; |
574 | } | ||
575 | } | ||
576 | |||
577 | void urlEncodeSpaces_String(iString *d) { | ||
578 | replaceAllChars_String_(d, ' ', "%20"); /* spaces */ | ||
579 | replaceAllChars_String_(d, '\n', "%0A"); /* newlines */ | ||
571 | } | 580 | } |
572 | 581 | ||
573 | const iString *withSpacesEncoded_String(const iString *d) { | 582 | const iString *withSpacesEncoded_String(const iString *d) { |
@@ -590,7 +599,8 @@ const iString *canonicalUrl_String(const iString *d) { | |||
590 | This means a canonical URL can be used on a gemtext link line without modifications. */ | 599 | This means a canonical URL can be used on a gemtext link line without modifications. */ |
591 | iString *canon = maybeUrlDecodeExclude_String(d, "/?:;#&= "); | 600 | iString *canon = maybeUrlDecodeExclude_String(d, "/?:;#&= "); |
592 | /* `canon` may now be NULL if nothing was decoded. */ | 601 | /* `canon` may now be NULL if nothing was decoded. */ |
593 | if (indexOfCStr_String(canon ? canon : d, " ") != iInvalidPos) { | 602 | if (indexOfCStr_String(canon ? canon : d, " ") != iInvalidPos || |
603 | indexOfCStr_String(canon ? canon : d, "\n") != iInvalidPos) { | ||
594 | if (!canon) { | 604 | if (!canon) { |
595 | canon = copy_String(d); | 605 | canon = copy_String(d); |
596 | } | 606 | } |