summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-15 06:44:31 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-15 06:44:31 +0300
commit5ae68c54e3b56d79307a9dea88570347b16973dd (patch)
tree667bcffa0b2d7df92b6ebb55389bfdf8759e71ae /src
parent2738d45e11d80d629668ca190e2b04e200ac2dfb (diff)
Fixed whitespace encoding in query string
Diffstat (limited to 'src')
-rw-r--r--src/gmutil.c20
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
564void urlEncodeSpaces_String(iString *d) { 564static 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
577void urlEncodeSpaces_String(iString *d) {
578 replaceAllChars_String_(d, ' ', "%20"); /* spaces */
579 replaceAllChars_String_(d, '\n', "%0A"); /* newlines */
571} 580}
572 581
573const iString *withSpacesEncoded_String(const iString *d) { 582const 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 }