--- src/LYMainLoop.c 2011-06-13 01:18:54.000000000 +0100 +++ /home/mark/src/lynx2-8-8/src/LYMainLoop.c 2012-01-14 23:13:37.211915974 +0000 @@ -3400,6 +3400,45 @@ } #endif +static const char *hexy = "0123456789ABCDEF"; +#define HEX(n) hexy[n] +static char *urlencode(char *str) +{ + // use 3x size of str, assuming every character of str needs to be encoded + // need 3 characters to encode each. + char *encoded = malloc(strlen(str) * 3 + 1), + *ptr = encoded; + + assert(encoded); + + while (*str) + { + if (*str == ' ') + { + *encoded = '+'; + encoded++; + } + else if ((*str != '.' && *str != '-' && *str != '~' && *str != '_') + && + (*str < 57 || (*str > 65 && *str < 97) || *str > 122)) + { + *encoded++ = '%'; + *encoded++ = HEX((*str >> 4)); + *encoded++ = HEX((*str & 0xF)); + } + else + { + *encoded++ = *str; + } + + str++; + } + + *encoded = '\0'; + + return ptr; +} + static BOOLEAN handle_LYK_JUMP(int c, char *user_input_buffer, char **old_user_input GCC_UNUSED, @@ -3446,11 +3485,32 @@ FREE(ret); return TRUE; } -#endif /* PERMIT_GOTO_FROM_JUMP */ +#endif /* PERMIT_GOTO_FROM_JUMP */ ret = HTParse(ret, startfile, PARSE_ALL); if (!LYTrimStartfile(ret)) { LYRemoveBlanks(user_input_buffer); } + if (strstr(ret, "%s")) { + int query_len = 0; + char input[100]; + RecallType recall = NORECALL; + + statusline("Query: "); + if (LYGetStr(input, VISIBLE, 100, recall) < 0) { + HTInfoMsg(CANCELLED); + } + else { + char *encoded = urlencode(input), + *sub_ret = NULL; + + // -2, for %s replacement + ret = realloc(ret, strlen(ret) + strlen(encoded) - 2); + sub_ret = malloc(strlen(ret) + strlen(encoded) - 2); + + strncpy(sub_ret, ret, strlen(ret)); + sprintf(ret, sub_ret, encoded); + } + } set_address(&newdoc, ret); StrAllocCopy(lynxjumpfile, ret); LYFreePostData(&newdoc);