Fossil SCM
Improved comments on anchor-generation routines like href(). Simplify the logic. Fix a bug in the generation of form elements for the /register page.
Commit
8dd75428928cb4a5383d27f160758e9c6aa3036906845af5ee1d85271d467807
Parent
ce15e35e4729ffa…
2 files changed
+1
+58
-21
+1
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -1778,10 +1778,11 @@ | ||
| 1778 | 1778 | zDecoded = captcha_decode(uSeed); |
| 1779 | 1779 | zCaptcha = captcha_render(zDecoded); |
| 1780 | 1780 | |
| 1781 | 1781 | style_header("Register"); |
| 1782 | 1782 | /* Print out the registration form. */ |
| 1783 | + g.perm.Hyperlink = 1; /* Artificially enable hyperlinks */ | |
| 1783 | 1784 | form_begin(0, "%R/register"); |
| 1784 | 1785 | if( P("g") ){ |
| 1785 | 1786 | @ <input type="hidden" name="g" value="%h(P("g"))" /> |
| 1786 | 1787 | } |
| 1787 | 1788 | @ <p><input type="hidden" name="captchaseed" value="%u(uSeed)" /> |
| 1788 | 1789 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -1778,10 +1778,11 @@ | |
| 1778 | zDecoded = captcha_decode(uSeed); |
| 1779 | zCaptcha = captcha_render(zDecoded); |
| 1780 | |
| 1781 | style_header("Register"); |
| 1782 | /* Print out the registration form. */ |
| 1783 | form_begin(0, "%R/register"); |
| 1784 | if( P("g") ){ |
| 1785 | @ <input type="hidden" name="g" value="%h(P("g"))" /> |
| 1786 | } |
| 1787 | @ <p><input type="hidden" name="captchaseed" value="%u(uSeed)" /> |
| 1788 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -1778,10 +1778,11 @@ | |
| 1778 | zDecoded = captcha_decode(uSeed); |
| 1779 | zCaptcha = captcha_render(zDecoded); |
| 1780 | |
| 1781 | style_header("Register"); |
| 1782 | /* Print out the registration form. */ |
| 1783 | g.perm.Hyperlink = 1; /* Artificially enable hyperlinks */ |
| 1784 | form_begin(0, "%R/register"); |
| 1785 | if( P("g") ){ |
| 1786 | @ <input type="hidden" name="g" value="%h(P("g"))" /> |
| 1787 | } |
| 1788 | @ <p><input type="hidden" name="captchaseed" value="%u(uSeed)" /> |
| 1789 |
+58
-21
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -107,27 +107,49 @@ | ||
| 107 | 107 | ** |
| 108 | 108 | ** <a href="URL"> |
| 109 | 109 | ** or <a id="ID"> |
| 110 | 110 | ** |
| 111 | 111 | ** The form of the anchor tag is determined by the g.javascriptHyperlink |
| 112 | -** variable. The href="URL" form is used if g.javascriptHyperlink is false. | |
| 113 | -** If g.javascriptHyperlink is true then the | |
| 114 | -** id="ID" form is used and javascript is generated in the footer to cause | |
| 115 | -** href values to be inserted after the page has loaded. If | |
| 116 | -** g.perm.History is false, then the <a id="ID"> form is still | |
| 117 | -** generated but the javascript is not generated so the links never | |
| 118 | -** activate. | |
| 112 | +** and g.perm.Hyperlink variables. | |
| 113 | +** | |
| 114 | +** g.perm.Hyperlink g.javascriptHyperlink Returned anchor format | |
| 115 | +** ---------------- --------------------- ------------------------ | |
| 116 | +** 0 0 (empty string) | |
| 117 | +** 0 1 (empty string) | |
| 118 | +** 1 0 <a href="URL"> | |
| 119 | +** 1 1 <a id="ID"> | |
| 120 | +** | |
| 121 | +** No anchor tag is generated if g.perm.Hyperlink is false. | |
| 122 | +** The href="URL" form is used if g.javascriptHyperlink is false. | |
| 123 | +** If g.javascriptHyperlink is true then the id="ID" form is used and | |
| 124 | +** javascript is generated in the footer to cause href values to be | |
| 125 | +** inserted after the page has loaded. The use of the id="ID" form | |
| 126 | +** instead of href="URL" is a defense against bots. | |
| 119 | 127 | ** |
| 120 | 128 | ** If the user lacks the Hyperlink (h) property and the "auto-hyperlink" |
| 121 | 129 | ** setting is true, then g.perm.Hyperlink is changed from 0 to 1 and |
| 122 | -** g.javascriptHyperlink is set to 1. The g.javascriptHyperlink defaults | |
| 123 | -** to 0 and only changes to one if the user lacks the Hyperlink (h) property | |
| 124 | -** and the "auto-hyperlink" setting is enabled. | |
| 130 | +** g.javascriptHyperlink is set to 1 by login_check_credentials(). Thus | |
| 131 | +** the g.perm.Hyperlink property will be true even if the user does not | |
| 132 | +** have the "h" privilege if the "auto-hyperlink" setting is true. | |
| 133 | +** | |
| 134 | +** User has "h" auto-hyperlink g.perm.Hyperlink g.javascriptHyperlink | |
| 135 | +** ------------ -------------- ---------------- --------------------- | |
| 136 | +** 0 0 0 0 | |
| 137 | +** 1 0 1 0 | |
| 138 | +** 0 1 1 1 | |
| 139 | +** 1 1 1 0 | |
| 140 | +** | |
| 141 | +** So, in other words, tracing input configuration to final actions we have: | |
| 142 | +** | |
| 143 | +** User has "h" auto-hyperlink Returned anchor format | |
| 144 | +** ------------ -------------- ---------------------- | |
| 145 | +** 0 0 (empty string) | |
| 146 | +** 1 0 <a href="URL"> | |
| 147 | +** 0 1 <a id="ID"> | |
| 148 | +** 1 1 (can't happen) | |
| 125 | 149 | ** |
| 126 | -** Filling in the href="URL" using javascript is a defense against bots. | |
| 127 | -** | |
| 128 | -** The name of this routine is deliberately kept short so that can be | |
| 150 | +** The name of these routines are deliberately kept short so that can be | |
| 129 | 151 | ** easily used within @-lines. Example: |
| 130 | 152 | ** |
| 131 | 153 | ** @ %z(href("%R/artifact/%s",zUuid))%h(zFN)</a> |
| 132 | 154 | ** |
| 133 | 155 | ** Note %z format. The string returned by this function is always |
| @@ -150,11 +172,11 @@ | ||
| 150 | 172 | va_list ap; |
| 151 | 173 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 152 | 174 | va_start(ap, zFormat); |
| 153 | 175 | zUrl = vmprintf(zFormat, ap); |
| 154 | 176 | va_end(ap); |
| 155 | - if( g.perm.Hyperlink && !g.javascriptHyperlink ){ | |
| 177 | + if( !g.javascriptHyperlink ){ | |
| 156 | 178 | char *zHUrl; |
| 157 | 179 | if( zExtra ){ |
| 158 | 180 | zHUrl = mprintf("<a %s href=\"%h\">", zExtra, zUrl); |
| 159 | 181 | }else{ |
| 160 | 182 | zHUrl = mprintf("<a href=\"%h\">", zUrl); |
| @@ -175,11 +197,11 @@ | ||
| 175 | 197 | va_list ap; |
| 176 | 198 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 177 | 199 | va_start(ap, zFormat); |
| 178 | 200 | zUrl = vmprintf(zFormat, ap); |
| 179 | 201 | va_end(ap); |
| 180 | - if( g.perm.Hyperlink && !g.javascriptHyperlink ){ | |
| 202 | + if( !g.javascriptHyperlink ){ | |
| 181 | 203 | char *zHUrl = mprintf("<a class=\"%s\" href=\"%h\">", zExtra, zUrl); |
| 182 | 204 | fossil_free(zUrl); |
| 183 | 205 | return zHUrl; |
| 184 | 206 | } |
| 185 | 207 | needHrefJs = 1; |
| @@ -191,11 +213,11 @@ | ||
| 191 | 213 | va_list ap; |
| 192 | 214 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 193 | 215 | va_start(ap, zFormat); |
| 194 | 216 | zUrl = vmprintf(zFormat, ap); |
| 195 | 217 | va_end(ap); |
| 196 | - if( g.perm.Hyperlink && !g.javascriptHyperlink ){ | |
| 218 | + if( !g.javascriptHyperlink ){ | |
| 197 | 219 | char *zHUrl = mprintf("<a href=\"%h\">", zUrl); |
| 198 | 220 | fossil_free(zUrl); |
| 199 | 221 | return zHUrl; |
| 200 | 222 | } |
| 201 | 223 | needHrefJs = 1; |
| @@ -202,23 +224,38 @@ | ||
| 202 | 224 | return mprintf("<a data-href='%s' href='%R/honeypot'>", |
| 203 | 225 | zUrl); |
| 204 | 226 | } |
| 205 | 227 | |
| 206 | 228 | /* |
| 207 | -** Generate <form method="post" action=ARG>. The ARG value is inserted | |
| 208 | -** by javascript. | |
| 229 | +** Generate <form method="post" action=ARG>. The ARG value is determined | |
| 230 | +** by the arguments. | |
| 231 | +** | |
| 232 | +** As a defense against robots, the action=ARG might instead by data-action=ARG | |
| 233 | +** and javascript (href.js) added to the page so that the data-action= is | |
| 234 | +** changed into action= after the page loads. Whether or not this happens | |
| 235 | +** depends on if the user has the "h" privilege and whether or not the | |
| 236 | +** auto-hyperlink setting is on. These setings determine the values of | |
| 237 | +** variables g.perm.Hyperlink and g.javascriptHyperlink. | |
| 238 | +** | |
| 239 | +** User has "h" auto-hyperlink g.perm.Hyperlink g.javascriptHyperlink | |
| 240 | +** ------------ -------------- ---------------- --------------------- | |
| 241 | +** 1: 0 0 0 0 | |
| 242 | +** 2: 1 0 1 0 | |
| 243 | +** 3: 0 1 1 1 | |
| 244 | +** 4: 1 1 1 0 | |
| 245 | +** | |
| 246 | +** The data-action=ARG form is used for cases 1 and 3. In case 1, the href.js | |
| 247 | +** javascript is omitted and so the form is effectively disabled. | |
| 209 | 248 | */ |
| 210 | 249 | void form_begin(const char *zOtherArgs, const char *zAction, ...){ |
| 211 | 250 | char *zLink; |
| 212 | 251 | va_list ap; |
| 213 | 252 | if( zOtherArgs==0 ) zOtherArgs = ""; |
| 214 | 253 | va_start(ap, zAction); |
| 215 | 254 | zLink = vmprintf(zAction, ap); |
| 216 | 255 | va_end(ap); |
| 217 | - if( fossil_strcmp(zLink,"/register")==0 | |
| 218 | - || (g.perm.Hyperlink && !g.javascriptHyperlink) | |
| 219 | - ){ | |
| 256 | + if( g.perm.Hyperlink ){ | |
| 220 | 257 | @ <form method="POST" action="%z(zLink)" %s(zOtherArgs)> |
| 221 | 258 | }else{ |
| 222 | 259 | needHrefJs = 1; |
| 223 | 260 | @ <form method="POST" data-action='%s(zLink)' action='%R/login' \ |
| 224 | 261 | @ %s(zOtherArgs)> |
| 225 | 262 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -107,27 +107,49 @@ | |
| 107 | ** |
| 108 | ** <a href="URL"> |
| 109 | ** or <a id="ID"> |
| 110 | ** |
| 111 | ** The form of the anchor tag is determined by the g.javascriptHyperlink |
| 112 | ** variable. The href="URL" form is used if g.javascriptHyperlink is false. |
| 113 | ** If g.javascriptHyperlink is true then the |
| 114 | ** id="ID" form is used and javascript is generated in the footer to cause |
| 115 | ** href values to be inserted after the page has loaded. If |
| 116 | ** g.perm.History is false, then the <a id="ID"> form is still |
| 117 | ** generated but the javascript is not generated so the links never |
| 118 | ** activate. |
| 119 | ** |
| 120 | ** If the user lacks the Hyperlink (h) property and the "auto-hyperlink" |
| 121 | ** setting is true, then g.perm.Hyperlink is changed from 0 to 1 and |
| 122 | ** g.javascriptHyperlink is set to 1. The g.javascriptHyperlink defaults |
| 123 | ** to 0 and only changes to one if the user lacks the Hyperlink (h) property |
| 124 | ** and the "auto-hyperlink" setting is enabled. |
| 125 | ** |
| 126 | ** Filling in the href="URL" using javascript is a defense against bots. |
| 127 | ** |
| 128 | ** The name of this routine is deliberately kept short so that can be |
| 129 | ** easily used within @-lines. Example: |
| 130 | ** |
| 131 | ** @ %z(href("%R/artifact/%s",zUuid))%h(zFN)</a> |
| 132 | ** |
| 133 | ** Note %z format. The string returned by this function is always |
| @@ -150,11 +172,11 @@ | |
| 150 | va_list ap; |
| 151 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 152 | va_start(ap, zFormat); |
| 153 | zUrl = vmprintf(zFormat, ap); |
| 154 | va_end(ap); |
| 155 | if( g.perm.Hyperlink && !g.javascriptHyperlink ){ |
| 156 | char *zHUrl; |
| 157 | if( zExtra ){ |
| 158 | zHUrl = mprintf("<a %s href=\"%h\">", zExtra, zUrl); |
| 159 | }else{ |
| 160 | zHUrl = mprintf("<a href=\"%h\">", zUrl); |
| @@ -175,11 +197,11 @@ | |
| 175 | va_list ap; |
| 176 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 177 | va_start(ap, zFormat); |
| 178 | zUrl = vmprintf(zFormat, ap); |
| 179 | va_end(ap); |
| 180 | if( g.perm.Hyperlink && !g.javascriptHyperlink ){ |
| 181 | char *zHUrl = mprintf("<a class=\"%s\" href=\"%h\">", zExtra, zUrl); |
| 182 | fossil_free(zUrl); |
| 183 | return zHUrl; |
| 184 | } |
| 185 | needHrefJs = 1; |
| @@ -191,11 +213,11 @@ | |
| 191 | va_list ap; |
| 192 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 193 | va_start(ap, zFormat); |
| 194 | zUrl = vmprintf(zFormat, ap); |
| 195 | va_end(ap); |
| 196 | if( g.perm.Hyperlink && !g.javascriptHyperlink ){ |
| 197 | char *zHUrl = mprintf("<a href=\"%h\">", zUrl); |
| 198 | fossil_free(zUrl); |
| 199 | return zHUrl; |
| 200 | } |
| 201 | needHrefJs = 1; |
| @@ -202,23 +224,38 @@ | |
| 202 | return mprintf("<a data-href='%s' href='%R/honeypot'>", |
| 203 | zUrl); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | ** Generate <form method="post" action=ARG>. The ARG value is inserted |
| 208 | ** by javascript. |
| 209 | */ |
| 210 | void form_begin(const char *zOtherArgs, const char *zAction, ...){ |
| 211 | char *zLink; |
| 212 | va_list ap; |
| 213 | if( zOtherArgs==0 ) zOtherArgs = ""; |
| 214 | va_start(ap, zAction); |
| 215 | zLink = vmprintf(zAction, ap); |
| 216 | va_end(ap); |
| 217 | if( fossil_strcmp(zLink,"/register")==0 |
| 218 | || (g.perm.Hyperlink && !g.javascriptHyperlink) |
| 219 | ){ |
| 220 | @ <form method="POST" action="%z(zLink)" %s(zOtherArgs)> |
| 221 | }else{ |
| 222 | needHrefJs = 1; |
| 223 | @ <form method="POST" data-action='%s(zLink)' action='%R/login' \ |
| 224 | @ %s(zOtherArgs)> |
| 225 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -107,27 +107,49 @@ | |
| 107 | ** |
| 108 | ** <a href="URL"> |
| 109 | ** or <a id="ID"> |
| 110 | ** |
| 111 | ** The form of the anchor tag is determined by the g.javascriptHyperlink |
| 112 | ** and g.perm.Hyperlink variables. |
| 113 | ** |
| 114 | ** g.perm.Hyperlink g.javascriptHyperlink Returned anchor format |
| 115 | ** ---------------- --------------------- ------------------------ |
| 116 | ** 0 0 (empty string) |
| 117 | ** 0 1 (empty string) |
| 118 | ** 1 0 <a href="URL"> |
| 119 | ** 1 1 <a id="ID"> |
| 120 | ** |
| 121 | ** No anchor tag is generated if g.perm.Hyperlink is false. |
| 122 | ** The href="URL" form is used if g.javascriptHyperlink is false. |
| 123 | ** If g.javascriptHyperlink is true then the id="ID" form is used and |
| 124 | ** javascript is generated in the footer to cause href values to be |
| 125 | ** inserted after the page has loaded. The use of the id="ID" form |
| 126 | ** instead of href="URL" is a defense against bots. |
| 127 | ** |
| 128 | ** If the user lacks the Hyperlink (h) property and the "auto-hyperlink" |
| 129 | ** setting is true, then g.perm.Hyperlink is changed from 0 to 1 and |
| 130 | ** g.javascriptHyperlink is set to 1 by login_check_credentials(). Thus |
| 131 | ** the g.perm.Hyperlink property will be true even if the user does not |
| 132 | ** have the "h" privilege if the "auto-hyperlink" setting is true. |
| 133 | ** |
| 134 | ** User has "h" auto-hyperlink g.perm.Hyperlink g.javascriptHyperlink |
| 135 | ** ------------ -------------- ---------------- --------------------- |
| 136 | ** 0 0 0 0 |
| 137 | ** 1 0 1 0 |
| 138 | ** 0 1 1 1 |
| 139 | ** 1 1 1 0 |
| 140 | ** |
| 141 | ** So, in other words, tracing input configuration to final actions we have: |
| 142 | ** |
| 143 | ** User has "h" auto-hyperlink Returned anchor format |
| 144 | ** ------------ -------------- ---------------------- |
| 145 | ** 0 0 (empty string) |
| 146 | ** 1 0 <a href="URL"> |
| 147 | ** 0 1 <a id="ID"> |
| 148 | ** 1 1 (can't happen) |
| 149 | ** |
| 150 | ** The name of these routines are deliberately kept short so that can be |
| 151 | ** easily used within @-lines. Example: |
| 152 | ** |
| 153 | ** @ %z(href("%R/artifact/%s",zUuid))%h(zFN)</a> |
| 154 | ** |
| 155 | ** Note %z format. The string returned by this function is always |
| @@ -150,11 +172,11 @@ | |
| 172 | va_list ap; |
| 173 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 174 | va_start(ap, zFormat); |
| 175 | zUrl = vmprintf(zFormat, ap); |
| 176 | va_end(ap); |
| 177 | if( !g.javascriptHyperlink ){ |
| 178 | char *zHUrl; |
| 179 | if( zExtra ){ |
| 180 | zHUrl = mprintf("<a %s href=\"%h\">", zExtra, zUrl); |
| 181 | }else{ |
| 182 | zHUrl = mprintf("<a href=\"%h\">", zUrl); |
| @@ -175,11 +197,11 @@ | |
| 197 | va_list ap; |
| 198 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 199 | va_start(ap, zFormat); |
| 200 | zUrl = vmprintf(zFormat, ap); |
| 201 | va_end(ap); |
| 202 | if( !g.javascriptHyperlink ){ |
| 203 | char *zHUrl = mprintf("<a class=\"%s\" href=\"%h\">", zExtra, zUrl); |
| 204 | fossil_free(zUrl); |
| 205 | return zHUrl; |
| 206 | } |
| 207 | needHrefJs = 1; |
| @@ -191,11 +213,11 @@ | |
| 213 | va_list ap; |
| 214 | if( !g.perm.Hyperlink ) return fossil_strdup(""); |
| 215 | va_start(ap, zFormat); |
| 216 | zUrl = vmprintf(zFormat, ap); |
| 217 | va_end(ap); |
| 218 | if( !g.javascriptHyperlink ){ |
| 219 | char *zHUrl = mprintf("<a href=\"%h\">", zUrl); |
| 220 | fossil_free(zUrl); |
| 221 | return zHUrl; |
| 222 | } |
| 223 | needHrefJs = 1; |
| @@ -202,23 +224,38 @@ | |
| 224 | return mprintf("<a data-href='%s' href='%R/honeypot'>", |
| 225 | zUrl); |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | ** Generate <form method="post" action=ARG>. The ARG value is determined |
| 230 | ** by the arguments. |
| 231 | ** |
| 232 | ** As a defense against robots, the action=ARG might instead by data-action=ARG |
| 233 | ** and javascript (href.js) added to the page so that the data-action= is |
| 234 | ** changed into action= after the page loads. Whether or not this happens |
| 235 | ** depends on if the user has the "h" privilege and whether or not the |
| 236 | ** auto-hyperlink setting is on. These setings determine the values of |
| 237 | ** variables g.perm.Hyperlink and g.javascriptHyperlink. |
| 238 | ** |
| 239 | ** User has "h" auto-hyperlink g.perm.Hyperlink g.javascriptHyperlink |
| 240 | ** ------------ -------------- ---------------- --------------------- |
| 241 | ** 1: 0 0 0 0 |
| 242 | ** 2: 1 0 1 0 |
| 243 | ** 3: 0 1 1 1 |
| 244 | ** 4: 1 1 1 0 |
| 245 | ** |
| 246 | ** The data-action=ARG form is used for cases 1 and 3. In case 1, the href.js |
| 247 | ** javascript is omitted and so the form is effectively disabled. |
| 248 | */ |
| 249 | void form_begin(const char *zOtherArgs, const char *zAction, ...){ |
| 250 | char *zLink; |
| 251 | va_list ap; |
| 252 | if( zOtherArgs==0 ) zOtherArgs = ""; |
| 253 | va_start(ap, zAction); |
| 254 | zLink = vmprintf(zAction, ap); |
| 255 | va_end(ap); |
| 256 | if( g.perm.Hyperlink ){ |
| 257 | @ <form method="POST" action="%z(zLink)" %s(zOtherArgs)> |
| 258 | }else{ |
| 259 | needHrefJs = 1; |
| 260 | @ <form method="POST" data-action='%s(zLink)' action='%R/login' \ |
| 261 | @ %s(zOtherArgs)> |
| 262 |