Skip to content

Commit

Permalink
Merge pull request #570 from bigbitecreative/feature/fix-encoding-issues
Browse files Browse the repository at this point in the history
Fix encoding issues which affect shortcodes and hashtags
  • Loading branch information
philipjohn authored Oct 26, 2018
2 parents 6fa2458 + e1052e2 commit 34e1eab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions classes/class-wpcom-liveblog-entry-extend-feature-hashtags.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ public function load() {
// the generated hashtag class.
$this->class_prefix = apply_filters( 'liveblog_hashtag_class', $this->class_prefix );

$prefixes = implode( '|', $this->get_prefixes() );

// Set a better regex for hashtags to allow for hex values in content -- see https://regex101.com/r/CLWsCo/
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- ignore indentation
$this->set_regex(
'~'
. '(?:'
. '(?<!\S)' // any visible character
. '|'
. '>?' // possible right angle bracket(s)
. ')'
. '(?:'
. '(?<!'
. '&' // literal ampersand
. '|'
. '&amp;' // encoded ampersand
. ')'
. ')'
. '('
. "(?:{$prefixes})" // hashtag prefixes
. '([0-9_\-\p{L}]*)' // 1: numerals, underscores, dashes, and any letter in any language
. ')'
. '~um'
);
// phpcs:enable

// This is the regex used to revert the
// generated hashtag html back to the
// raw input format (e.g #hashtag).
Expand Down
2 changes: 1 addition & 1 deletion classes/class-wpcom-liveblog-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public static function sanitize_numeric( $param, $request, $key ) {
*/
public static function get_json_param( $param, $json ) {
if ( isset( $json[ $param ] ) ) {
return $json[ $param ];
return html_entity_decode( $json[ $param ] );
}
return false;
}
Expand Down

0 comments on commit 34e1eab

Please sign in to comment.