Skip to content

Commit

Permalink
Merge pull request #1121 from INN/1076-twitter-urlencode-redux-redux
Browse files Browse the repository at this point in the history
Use rawurlencode for maximum redundancy.
  • Loading branch information
benlk committed Feb 5, 2016
2 parents 3a12b55 + 1c94a84 commit 6323e02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 10 additions & 8 deletions inc/post-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ function largo_post_social_links( $echo = true ) {
$fb_share = '<span class="facebook"><a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=%1$s"><i class="icon-facebook"></i><span class="hidden-phone">%2$s</span></a></span>';
$output .= sprintf(
$fb_share,
esc_attr( get_permalink() ),
esc_attr( ucfirst( of_get_option( 'fb_verb' ) ) )
// Yes, rawurlencode. Otherwise, the link will break.
rawurlencode( get_permalink() ),
rawurlencode( ucfirst( of_get_option( 'fb_verb' ) ) )
);
}

Expand All @@ -221,31 +222,32 @@ function largo_post_social_links( $echo = true ) {
}
}
if ( count( $author_twitters ) == 1 ) {
$via = '&via=' . esc_attr( largo_twitter_url_to_username( $author_twitters[0] ) );
$via = '&via=' . rawurlencode( largo_twitter_url_to_username( $author_twitters[0] ) );
}
// in the event that there are more than one author twitter accounts, we fall back to the org account
// @link https://github.com/INN/Largo/issues/1088
} else if ( !isset( $values['largo_byline_text'] ) ) {
$user = get_the_author_meta( 'twitter' );
if ( !empty( $user ) ) {
$via = '&via=' . esc_attr( largo_twitter_url_to_username( $user ) );
$via = '&via=' . rawurlencode( largo_twitter_url_to_username( $user ) );
}
}

// Use the site Twitter handle if that exists and there isn't yet a via
if ( empty( $via ) ) {
$site = of_get_option( 'twitter_link' );
if ( !empty( $site ) ) {
$via = '&via=' . esc_attr( largo_twitter_url_to_username( $site ) ) ;
$via = '&via=' . rawurlencode( largo_twitter_url_to_username( $site ) ) ;
}
}

$output .= sprintf(
$twitter_share,
esc_attr( get_the_title() ),
esc_attr( get_permalink() ),
// Yes, rawurlencode. Otherwise, the link will break.
rawurlencode( get_the_title() ),
rawurlencode( get_permalink() ),
$via,
esc_attr( __( 'Tweet', 'largo' ) )
rawurlencode( __( 'Tweet', 'largo' ) )
);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/inc/test-post-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function test_largo_post_social_links() {
$this->assertRegExp('/class="twitter"/' , $ret, "The 'twitter' class did not appear in the output");
// @TODO: insert a test for the get_the_author_meta test here
$this->assertRegExp('/' . __('Tweet', 'largo') . '/', $ret, "The translation of 'Tweet' was not in the Twitter output");
$this->assertRegExp('/' . preg_quote(rawurlencode(get_permalink()), '/') . '/', $ret, "The permalink was not in the Twitter output");
$this->assertRegExp('/' . preg_quote(rawurlencode(get_the_title()), '/') . '/', $ret, "The title was not in the Twitter output");
unset($ret);
of_reset_options();

Expand All @@ -89,7 +91,7 @@ function test_largo_post_social_links() {
largo_post_social_links();
$ret = ob_get_clean();
$this->assertRegExp('/' . preg_quote(esc_attr( of_get_option( 'fb_verb' ) ), '/' ) . '/i', $ret, "The Facebook Verb was not in the Facebook output");
$this->assertRegExp('/' . preg_quote(get_permalink(), '/') . '/', $ret, "The permalink was not in the Facebook output");
$this->assertRegExp('/' . preg_quote(rawurlencode(get_permalink()), '/') . '/', $ret, "The permalink was not in the Facebook output");
unset($ret);
of_reset_options();

Expand Down

0 comments on commit 6323e02

Please sign in to comment.