Fossil SCM
Add the "httpize" TH1 command, which does the same as Javascript's encodeURIComponent() function.
Commit
fc6bb9368953e5b6f9ebc8d97088ab320a90dc0e
Parent
a7a7df7072e1248…
1 file changed
+24
+24
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -97,10 +97,33 @@ | ||
| 97 | 97 | fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n"); |
| 98 | 98 | fossil_print("%s", blob_str(&g.thLog)); |
| 99 | 99 | fossil_print("\n------------------- END TRACE LOG -------------------\n"); |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | + | |
| 103 | +/* | |
| 104 | +** TH command: httpize STRING | |
| 105 | +** | |
| 106 | +** Escape all characters of STRING which have special meaning in URI | |
| 107 | +** components. Return a new string result. | |
| 108 | +*/ | |
| 109 | +static int httpizeCmd( | |
| 110 | + Th_Interp *interp, | |
| 111 | + void *p, | |
| 112 | + int argc, | |
| 113 | + const char **argv, | |
| 114 | + int *argl | |
| 115 | +){ | |
| 116 | + char *zOut; | |
| 117 | + if( argc!=2 ){ | |
| 118 | + return Th_WrongNumArgs(interp, "httpize STRING"); | |
| 119 | + } | |
| 120 | + zOut = httpize((char*)argv[1], argl[1]); | |
| 121 | + Th_SetResult(interp, zOut, -1); | |
| 122 | + free(zOut); | |
| 123 | + return TH_OK; | |
| 124 | +} | |
| 102 | 125 | |
| 103 | 126 | /* |
| 104 | 127 | ** True if output is enabled. False if disabled. |
| 105 | 128 | */ |
| 106 | 129 | static int enableOutput = 1; |
| @@ -972,10 +995,11 @@ | ||
| 972 | 995 | {"anycap", anycapCmd, 0}, |
| 973 | 996 | {"combobox", comboboxCmd, 0}, |
| 974 | 997 | {"date", dateCmd, 0}, |
| 975 | 998 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 976 | 999 | {"enable_output", enableOutputCmd, 0}, |
| 1000 | + {"httpize", httpizeCmd, 0}, | |
| 977 | 1001 | {"hascap", hascapCmd, 0}, |
| 978 | 1002 | {"hasfeature", hasfeatureCmd, 0}, |
| 979 | 1003 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 980 | 1004 | {"htmlize", htmlizeCmd, 0}, |
| 981 | 1005 | {"http", httpCmd, 0}, |
| 982 | 1006 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -97,10 +97,33 @@ | |
| 97 | fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n"); |
| 98 | fossil_print("%s", blob_str(&g.thLog)); |
| 99 | fossil_print("\n------------------- END TRACE LOG -------------------\n"); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | ** True if output is enabled. False if disabled. |
| 105 | */ |
| 106 | static int enableOutput = 1; |
| @@ -972,10 +995,11 @@ | |
| 972 | {"anycap", anycapCmd, 0}, |
| 973 | {"combobox", comboboxCmd, 0}, |
| 974 | {"date", dateCmd, 0}, |
| 975 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 976 | {"enable_output", enableOutputCmd, 0}, |
| 977 | {"hascap", hascapCmd, 0}, |
| 978 | {"hasfeature", hasfeatureCmd, 0}, |
| 979 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 980 | {"htmlize", htmlizeCmd, 0}, |
| 981 | {"http", httpCmd, 0}, |
| 982 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -97,10 +97,33 @@ | |
| 97 | fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n"); |
| 98 | fossil_print("%s", blob_str(&g.thLog)); |
| 99 | fossil_print("\n------------------- END TRACE LOG -------------------\n"); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | ** TH command: httpize STRING |
| 105 | ** |
| 106 | ** Escape all characters of STRING which have special meaning in URI |
| 107 | ** components. Return a new string result. |
| 108 | */ |
| 109 | static int httpizeCmd( |
| 110 | Th_Interp *interp, |
| 111 | void *p, |
| 112 | int argc, |
| 113 | const char **argv, |
| 114 | int *argl |
| 115 | ){ |
| 116 | char *zOut; |
| 117 | if( argc!=2 ){ |
| 118 | return Th_WrongNumArgs(interp, "httpize STRING"); |
| 119 | } |
| 120 | zOut = httpize((char*)argv[1], argl[1]); |
| 121 | Th_SetResult(interp, zOut, -1); |
| 122 | free(zOut); |
| 123 | return TH_OK; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | ** True if output is enabled. False if disabled. |
| 128 | */ |
| 129 | static int enableOutput = 1; |
| @@ -972,10 +995,11 @@ | |
| 995 | {"anycap", anycapCmd, 0}, |
| 996 | {"combobox", comboboxCmd, 0}, |
| 997 | {"date", dateCmd, 0}, |
| 998 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 999 | {"enable_output", enableOutputCmd, 0}, |
| 1000 | {"httpize", httpizeCmd, 0}, |
| 1001 | {"hascap", hascapCmd, 0}, |
| 1002 | {"hasfeature", hasfeatureCmd, 0}, |
| 1003 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 1004 | {"htmlize", htmlizeCmd, 0}, |
| 1005 | {"http", httpCmd, 0}, |
| 1006 |