Skip to content

Commit

Permalink
Merge pull request #27 from beetlebugorg/bugfix/handle-percent20-enco…
Browse files Browse the repository at this point in the history
…ding

Convert spaces to '+' in crop commands
  • Loading branch information
Jeremy Collins authored Nov 11, 2019
2 parents a4b3d0d + 292c2d9 commit 8fc94a3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/mod_dims.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,19 @@ dims_handle_request(dims_request_rec *d)
}
}

// Convert %20 (space) back to '+' in commands. This is fixes an issue with "+" being encoded as %20 by some clients.
char *commands = apr_pstrdup(d->r->pool, d->unparsed_commands);
char *s = commands;
while (*s) {
if (*s == ' ') {
*s = '+';
}

s++;
}

// Standard signature params.
char *signature_params = apr_pstrcat(d->pool, expires_str, d->client_config->secret_key, d->unparsed_commands, d->image_url, NULL);
char *signature_params = apr_pstrcat(d->pool, expires_str, d->client_config->secret_key, commands, d->image_url, NULL);

// Concatenate additional params.
char *token;
Expand Down
19 changes: 19 additions & 0 deletions src/mod_dims_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,25 @@ dims_crop_operation (dims_request_rec *d, char *args, char **err) {
RectangleInfo rec;
ExceptionInfo ex_info;

/* Replace spaces with '+'. This happens when some user agents inadvertantly
* escape the '+' as %20 which gets converted to a space.
*
* Example:
*
* 900x900%20350%200 is '900x900 350 0' which is an invalid, the following code
* coverts this to '900x900+350+0'.
*
*/
char *s = args;
while (*s) {
if (*s == ' ') {
*s = '+';
}

s++;
}


flags = ParseGravityGeometry(GetImageFromMagickWand(d->wand), args, &rec, &ex_info);
if(!(flags & AllValues)) {
*err = "Parsing crop geometry failed";
Expand Down

0 comments on commit 8fc94a3

Please sign in to comment.