BBlack has uploaded a new change for review.
https://gerrit.wikimedia.org/r/274088
Change subject: normalize_path: refactor control flow
......................................................................
normalize_path: refactor control flow
Bug: T127387
Change-Id: Ia41bbc05d47ca0594df2a1ccca3cb01a84d0a73b
---
M templates/varnish/normalize_path.inc.vcl.erb
1 file changed, 9 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/88/274088/1
diff --git a/templates/varnish/normalize_path.inc.vcl.erb
b/templates/varnish/normalize_path.inc.vcl.erb
index 2f44e64..6970310 100644
--- a/templates/varnish/normalize_path.inc.vcl.erb
+++ b/templates/varnish/normalize_path.inc.vcl.erb
@@ -27,7 +27,6 @@
const size_t urlLength = strlen(url);
// index for the last position %XX can start at:
const size_t lastConvertIdx = urlLength > 2 ? urlLength - 3 : 0;
- char c;
int dirty = 0;
/* Allocate destination memory from the stack using the C99
@@ -35,9 +34,9 @@
* because this function can only shorten the input string.
*/
char destBuffer[urlLength + 1];
- for (i = 0, outPos = 0; i < urlLength; i++) {
+ while (url[i] && url[i] != '?' && url[i] != '#') {
if (i <= lastConvertIdx && url[i] == '%' && NP_IS_HEX(url[i+1])
&& NP_IS_HEX(url[i+2])) {
- c = NP_HEXCHAR(url[i+1], url[i+2]);
+ const char c = NP_HEXCHAR(url[i+1], url[i+2]);
if (c == ';'
|| c == '@'
|| c == '$'
@@ -51,22 +50,18 @@
{
destBuffer[outPos++] = c;
dirty = 1;
- i += 2;
+ i += 3;
} else {
- destBuffer[outPos++] = url[i];
+ destBuffer[outPos++] = url[i++];
}
- } else if (url[i] == '?' || url[i] = '#') {
- /* Reached the query/frag part. Just copy the rest of
the URL
- * to the destination.
- */
- memcpy(destBuffer + outPos, url + i, sizeof(char) *
(urlLength - i));
- outPos += urlLength - i;
- i = urlLength;
} else {
- destBuffer[outPos++] = url[i];
+ destBuffer[outPos++] = url[i++];
}
}
- destBuffer[outPos] = '\0';
+
+ // copy remainder (query/frag + terminal NUL)
+ const unsigned bytesLeftover = 1 + urlLength - i;
+ memcpy(destBuffer + outPos, url + i, bytesLeftover)
/* Set req.url. This will copy our stack buffer into the workspace.
* VRT_l_req_url() is varadic, and concatenates its arguments. The
--
To view, visit https://gerrit.wikimedia.org/r/274088
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia41bbc05d47ca0594df2a1ccca3cb01a84d0a73b
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BBlack <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits