Skip to content

Commit

Permalink
Merge pull request #67 from humanmade/urlencode-params
Browse files Browse the repository at this point in the history
URL encode argument values
  • Loading branch information
roborourke authored Mar 26, 2021
2 parents 5717f79 + 0cf2bdd commit ef3a45e
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 114 deletions.
4 changes: 2 additions & 2 deletions tachyon.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ function tachyon_url( $image_url, $args = array(), $scheme = null ) {
$args = apply_filters( 'tachyon_pre_args', $args, $image_url, $scheme );

$tachyon_url = str_replace( $upload_baseurl, TACHYON_URL, $image_url );

if ( $args ) {
if ( is_array( $args ) ) {
$tachyon_url = add_query_arg( $args, $tachyon_url );
// URL encode all param values, as this is not handled by add_query_arg.
$tachyon_url = add_query_arg( array_map( 'rawurlencode', $args ), $tachyon_url );
} else {
// You can pass a query string for complicated requests but where you still want CDN subdomain help, etc.
$tachyon_url .= '?' . $args;
Expand Down
12 changes: 6 additions & 6 deletions tests/tests/class-linking.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ function data_content_filtering() {
'<p><a href="%%BASE_URL%%/tachyon.jpg"><img class="alignnone size-thumbnail wp-image-%%ID%%" src="%%BASE_URL%%/tachyon-150x150.jpg" alt="" width="150" height="150" /></a></p>',
[
'http://tachy.on/u/tachyon.jpg',
'http://tachy.on/u/tachyon.jpg?resize=1280,719',
'http://tachy.on/u/tachyon.jpg?resize=1280%2C719',
],
[
'http://tachy.on/u/tachyon.jpg?resize=150,150',
'http://tachy.on/u/tachyon.jpg?resize=150%2C150',
],
],
// Block editor linked thumbnail.
Expand All @@ -155,10 +155,10 @@ function data_content_filtering() {
'<figure class="wp-block-image size-medium"><a href="%%BASE_URL%%/tachyon.jpg"><img src="%%BASE_URL%%/tachyon-150x150.jpg" alt="" class="wp-image-%%ID%%"/></a></figure>',
[
'http://tachy.on/u/tachyon.jpg',
'http://tachy.on/u/tachyon.jpg?resize=1280,719',
'http://tachy.on/u/tachyon.jpg?resize=1280%2C719',
],
[
'http://tachy.on/u/tachyon.jpg?resize=150,150',
'http://tachy.on/u/tachyon.jpg?resize=150%2C150',
],
],
// Block editor gallery.
Expand All @@ -167,10 +167,10 @@ function data_content_filtering() {
'<figure class="wp-block-gallery columns-1 is-cropped"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="%%BASE_URL%%/tachyon.jpg"><img src="%%BASE_URL%%/tachyon-1024x575.jpg" alt="" data-id="%%ID%%" data-full-url="%%BASE_URL%%/tachyon.jpg" data-link="http://milstead.local/2019/12/26/classic-test/tachyon/" class="wp-image-%%ID%%"/></a></figure></li></ul></figure>',
[
'http://tachy.on/u/tachyon.jpg',
'http://tachy.on/u/tachyon.jpg?resize=1280,719',
'http://tachy.on/u/tachyon.jpg?resize=1280%2C719',
],
[
'http://tachy.on/u/tachyon.jpg?resize=1024,575',
'http://tachy.on/u/tachyon.jpg?resize=1024%2C575',
],
],
];
Expand Down
Loading

0 comments on commit ef3a45e

Please sign in to comment.