<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[32863] trunk: `wptexturize()` improvements:</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/32863">32863</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/32863","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>wonderboymusic</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-06-19 20:05:52 +0000 (Fri, 19 Jun 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>`wptexturize()` improvements:
* Make sure that strings ending with a number and quotation mark get the proper smart quotes
* Introduce `wptexturize_primes()`, a logic tree to determine whether or not "7'." represents seven feet, then converts the special char into either a prime char or a closing quote char.
Adds unit tests.
Props miqrogroove.
Fixes <a href="https://core.trac.wordpress.org/ticket/29256">#29256</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesformattingphp">trunk/src/wp-includes/formatting.php</a></li>
<li><a href="#trunktestsphpunittestsformattingWPTexturizephp">trunk/tests/phpunit/tests/formatting/WPTexturize.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesformattingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/formatting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/formatting.php 2015-06-19 18:55:52 UTC (rev 32862)
+++ trunk/src/wp-includes/formatting.php 2015-06-19 20:05:52 UTC (rev 32863)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,7 +46,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $dynamic_replacements = null,
</span><span class="cx" style="display: block; padding: 0 10px"> $default_no_texturize_tags = null,
</span><span class="cx" style="display: block; padding: 0 10px"> $default_no_texturize_shortcodes = null,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $run_texturize = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $run_texturize = true,
+ $apos = null,
+ $prime = null,
+ $double_prime = null,
+ $opening_quote = null,
+ $closing_quote = null,
+ $opening_single_quote = null,
+ $closing_single_quote = null,
+ $open_q_flag = '<!--oq-->',
+ $open_sq_flag = '<!--osq-->',
+ $apos_flag = '<!--apos-->';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If there's nothing to do, just stop.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $text ) || false === $run_texturize ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -129,66 +139,46 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( "'" !== $apos || "'" !== $closing_single_quote ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/\'(\d\d)\'(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/\'(\d\d)\'(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_single_quote;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( "'" !== $apos || '"' !== $closing_quote ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/\'(\d\d)"(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/\'(\d\d)"(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_quote;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // '99 '99s '99's (apostrophe) But never '9 or '99% or '999 or '99.0.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( "'" !== $apos ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/' ] = $apos;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/' ] = $apos_flag;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Quoted Numbers like '0.42'
</span><span class="cx" style="display: block; padding: 0 10px"> if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $open_sq_flag . '$1' . $closing_single_quote;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Single quote at start, or preceded by (, {, <, [, ", -, or spaces.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( "'" !== $opening_single_quote ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/(?<=\A|[([{"\-]|<|' . $spaces . ')\'/' ] = $opening_single_quote;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/(?<=\A|[([{"\-]|<|' . $spaces . ')\'/' ] = $open_sq_flag;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Apostrophe in a word. No spaces, double apostrophes, or other punctuation.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( "'" !== $apos ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos_flag;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 9' (prime)
- if ( "'" !== $prime ) {
- $dynamic[ '/(?<=\d)\'/' ] = $prime;
- }
-
- // Single quotes followed by spaces or ending punctuation.
- if ( "'" !== $closing_single_quote ) {
- $dynamic[ '/\'(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $closing_single_quote;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $dynamic_characters['apos'] = array_keys( $dynamic );
</span><span class="cx" style="display: block; padding: 0 10px"> $dynamic_replacements['apos'] = array_values( $dynamic );
</span><span class="cx" style="display: block; padding: 0 10px"> $dynamic = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Quoted Numbers like "42"
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $opening_quote . '$1' . $closing_quote;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $open_q_flag . '$1' . $closing_quote;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 9" (double prime)
- if ( '"' !== $double_prime ) {
- $dynamic[ '/(?<=\d)"/' ] = $double_prime;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '"' !== $opening_quote ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $dynamic[ '/(?<=\A|[([{\-]|<|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $dynamic[ '/(?<=\A|[([{\-]|<|' . $spaces . ')"(?!' . $spaces . ')/' ] = $open_q_flag;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Any remaining double quotes.
- if ( '"' !== $closing_quote ) {
- $dynamic[ '/"/' ] = $closing_quote;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $dynamic_characters['quote'] = array_keys( $dynamic );
</span><span class="cx" style="display: block; padding: 0 10px"> $dynamic_replacements['quote'] = array_values( $dynamic );
</span><span class="cx" style="display: block; padding: 0 10px"> $dynamic = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -300,9 +290,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false !== strpos( $curl, "'" ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $curl = wptexturize_primes( $curl, "'", $prime, $open_sq_flag, $closing_single_quote );
+ $curl = str_replace( $apos_flag, $apos, $curl );
+ $curl = str_replace( $open_sq_flag, $opening_single_quote, $curl );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false !== strpos( $curl, '"' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $curl = preg_replace( $dynamic_characters['quote'], $dynamic_replacements['quote'], $curl );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $curl = wptexturize_primes( $curl, '"', $double_prime, $open_q_flag, $closing_quote );
+ $curl = str_replace( $open_q_flag, $opening_quote, $curl );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false !== strpos( $curl, '-' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $curl = preg_replace( $dynamic_characters['dash'], $dynamic_replacements['dash'], $curl );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -322,6 +317,74 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Implements a logic tree to determine whether or not "7'." represents seven feet,
+ * then converts the special char into either a prime char or a closing quote char.
+ *
+ * @since 4.3.0
+ *
+ * @param string $haystack The plain text to be searched.
+ * @param string $needle The character to search for such as ' or ".
+ * @param string $prime The prime char to use for replacement.
+ * @param string $open_quote The opening quote char. Opening quote replacement must be accomplished already.
+ * @param string $close_quote The closing quote char to use for replacement.
+ * @return string The $haystack value after primes and quotes replacements.
+ */
+function wptexturize_primes( $haystack, $needle, $prime, $open_quote, $close_quote ) {
+ $spaces = wp_spaces_regexp();
+ $flag = '<!--wp-prime-or-quote-->';
+ $quote_pattern = "/$needle(?=\\Z|[.,:;!?)}\\-\\]]|>|" . $spaces . ")/";
+ $prime_pattern = "/(?<=\\d)$needle/";
+ $flag_after_digit = "/(?<=\\d)$flag/";
+ $flag_no_digit = "/(?<!\\d)$flag/";
+
+ $sentences = explode( $open_quote, $haystack );
+
+ foreach( $sentences as $key => &$sentence ) {
+ if ( false === strpos( $sentence, $needle ) ) {
+ continue;
+ } elseif ( 0 !== $key && 0 === substr_count( $sentence, $close_quote ) ) {
+ $sentence = preg_replace( $quote_pattern, $flag, $sentence, -1, $count );
+ if ( $count > 1 ) {
+ // This sentence appears to have multiple closing quotes. Attempt Vulcan logic.
+ $sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, -1, $count2 );
+ if ( 0 === $count2 ) {
+ // Try looking for a quote followed by a period.
+ $count2 = substr_count( $sentence, "$flag." );
+ if ( $count2 > 0 ) {
+ // Assume the rightmost quote-period match is the end of quotation.
+ $pos = strrpos( $sentence, "$flag." );
+ } else {
+ // When all else fails, make the rightmost candidate a closing quote.
+ // This is most likely to be problematic in the context of bug #18549.
+ $pos = strrpos( $sentence, $flag );
+ }
+ $sentence = substr_replace( $sentence, $close_quote, $pos, strlen( $flag ) );
+ }
+ // Use conventional replacement on any remaining primes and quotes.
+ $sentence = preg_replace( $prime_pattern, $prime, $sentence );
+ $sentence = preg_replace( $flag_after_digit, $prime, $sentence );
+ $sentence = str_replace( $flag, $close_quote, $sentence );
+ } elseif ( 1 == $count ) {
+ // Found only one closing quote candidate, so give it priority over primes.
+ $sentence = str_replace( $flag, $close_quote, $sentence );
+ $sentence = preg_replace( $prime_pattern, $prime, $sentence );
+ } else {
+ // No closing quotes found. Just run primes pattern.
+ $sentence = preg_replace( $prime_pattern, $prime, $sentence );
+ }
+ } else {
+ $sentence = preg_replace( $prime_pattern, $prime, $sentence );
+ $sentence = preg_replace( $quote_pattern, $close_quote, $sentence );
+ }
+ if ( '"' == $needle && false !== strpos( $sentence, '"' ) ) {
+ $sentence = str_replace( '"', $close_quote, $sentence );
+ }
+ }
+
+ return implode( $open_quote, $sentences );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Search for disabled element tags. Push element to stack on tag open and pop
</span><span class="cx" style="display: block; padding: 0 10px"> * on tag close.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunktestsphpunittestsformattingWPTexturizephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/formatting/WPTexturize.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/formatting/WPTexturize.php 2015-06-19 18:55:52 UTC (rev 32862)
+++ trunk/tests/phpunit/tests/formatting/WPTexturize.php 2015-06-19 20:05:52 UTC (rev 32863)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -90,8 +90,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> //$this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”… and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.'));
</span><span class="cx" style="display: block; padding: 0 10px"> //$this->assertEquals('Here is “a test <a href="http://example.com">with a link</a>”.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".'));
</span><span class="cx" style="display: block; padding: 0 10px"> //$this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.'));
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //$this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".'));
- //$this->assertEquals('A test with a number, “like 62”, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.'));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".'));
+ $this->assertEquals('A test with a number, “like 62”, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.'));
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -121,7 +121,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals('‘Class of ’99’?', wptexturize("'Class of '99'?"));
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'"));
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'"));
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //$this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\""));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\""));
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\""));
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals('{“Class of ’99”}', wptexturize("{\"Class of '99\"}"));
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals(' “Class of ’99” ', wptexturize(" \"Class of '99\" "));
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1900,4 +1900,152 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Ensure primes logic is not too greedy at the end of a quotation.
+ *
+ * @ticket 29256
+ * @dataProvider data_primes_vs_quotes
+ */
+ function test_primes_vs_quotes( $input, $output ) {
+ return $this->assertEquals( $output, wptexturize( $input ) );
+ }
+
+ function data_primes_vs_quotes() {
+ return array(
+ array(
+ "George's porch is 99' long.",
+ "George’s porch is 99′ long.",
+ ),
+ array(
+ 'The best year "was that time in 2012" when everyone partied, he said.',
+ 'The best year “was that time in 2012” when everyone partied, he said.',
+ ),
+ array(
+ "I need 4 x 20' = 80' of trim.", // Works only with a space before the = char.
+ "I need 4 x 20′ = 80′ of trim.",
+ ),
+ array(
+ '"Lorem ipsum dolor sit amet 1234"',
+ '“Lorem ipsum dolor sit amet 1234”',
+ ),
+ array(
+ "'Etiam eu egestas dui 1234'",
+ "‘Etiam eu egestas dui 1234’",
+ ),
+ array(
+ 'according to our source, "33% of all students scored less than 50" on the test.',
+ 'according to our source, “33% of all students scored less than 50” on the test.',
+ ),
+ array(
+ "The doctor said, 'An average height is between 5' and 6' in study group 7'. He then produced a 6' chart of averages. A man of 7', incredibly, is very possible.",
+ "The doctor said, ‘An average height is between 5′ and 6′ in study group 7’. He then produced a 6′ chart of averages. A man of 7′, incredibly, is very possible.",
+ ),
+ array(
+ 'Pirates have voted on "The Expendables 3" with their clicks -- and it turns out the Sylvester Stallone-starrer hasn\'t been astoundingly popular among digital thieves, relatively speaking.
+
+As of Sunday, 5.12 million people worldwide had pirated "Expendables 3" since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
+
+That likely contributed to the action movie\'s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after "Captain America: The Winter Soldier" (7.31 million), "Divergent" (6.29 million) and "The Amazing Spider-Man 2" (5.88 million). Moreover, that\'s despite "Expendables 3" becoming available more than three weeks prior to the film\'s U.S. theatrical debut.
+
+String with a number followed by a single quote \'Expendables 3\' vestibulum in arcu mi.',
+
+ 'Pirates have voted on “The Expendables 3” with their clicks — and it turns out the Sylvester Stallone-starrer hasn’t been astoundingly popular among digital thieves, relatively speaking.
+
+As of Sunday, 5.12 million people worldwide had pirated “Expendables 3” since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
+
+That likely contributed to the action movie’s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after “Captain America: The Winter Soldier” (7.31 million), “Divergent” (6.29 million) and “The Amazing Spider-Man 2” (5.88 million). Moreover, that’s despite “Expendables 3” becoming available more than three weeks prior to the film’s U.S. theatrical debut.
+
+String with a number followed by a single quote ‘Expendables 3’ vestibulum in arcu mi.',
+ ),
+ );
+ }
+
+ /**
+ * Make sure translation actually works.
+ *
+ * Also make sure opening and closing quotes are allowed to be identical.
+ *
+ * @ticket 29256
+ * @dataProvider data_primes_quotes_translation
+ */
+ function test_primes_quotes_translation( $input, $output ) {
+ add_filter( 'gettext_with_context', array( $this, 'filter_translate2' ), 10, 4 );
+
+ $result = wptexturize( $input, true );
+
+ remove_filter( 'gettext_with_context', array( $this, 'filter_translate2' ), 10, 4 );
+ wptexturize( 'reset', true );
+
+ return $this->assertEquals( $output, $result );
+ }
+
+ function filter_translate2( $translations, $text, $context, $domain ) {
+ switch ($text) {
+ case '–' : return '!endash!';
+ case '—' : return '!emdash!';
+ case '‘' : return '!q1!';
+ case '’' :
+ if ( 'apostrophe' == $context ) {
+ return '!apos!';
+ } else {
+ return '!q1!';
+ }
+ case '“' : return '!q2!';
+ case '”' : return '!q2!';
+ case '′' : return '!prime1!';
+ case '″' : return '!prime2!';
+ default : return $translations;
+ }
+ }
+
+ function data_primes_quotes_translation() {
+ return array(
+ array(
+ "George's porch is 99' long.",
+ "George!apos!s porch is 99!prime1! long.",
+ ),
+ array(
+ 'The best year "was that time in 2012" when everyone partied, he said.',
+ 'The best year !q2!was that time in 2012!q2! when everyone partied, he said.',
+ ),
+ array(
+ "I need 4 x 20' = 80' of trim.", // Works only with a space before the = char.
+ "I need 4 x 20!prime1! = 80!prime1! of trim.",
+ ),
+ array(
+ '"Lorem ipsum dolor sit amet 1234"',
+ '!q2!Lorem ipsum dolor sit amet 1234!q2!',
+ ),
+ array(
+ "'Etiam eu egestas dui 1234'",
+ "!q1!Etiam eu egestas dui 1234!q1!",
+ ),
+ array(
+ 'according to our source, "33% of all students scored less than 50" on the test.',
+ 'according to our source, !q2!33% of all students scored less than 50!q2! on the test.',
+ ),
+ array(
+ "The doctor said, 'An average height is between 5' and 6' in study group 7'. He then produced a 6' chart of averages. A man of 7', incredibly, is very possible.",
+ "The doctor said, !q1!An average height is between 5!prime1! and 6!prime1! in study group 7!q1!. He then produced a 6!prime1! chart of averages. A man of 7!prime1!, incredibly, is very possible.",
+ ),
+ array(
+ 'Pirates have voted on "The Expendables 3" with their clicks -- and it turns out the Sylvester Stallone-starrer hasn\'t been astoundingly popular among digital thieves, relatively speaking.
+
+As of Sunday, 5.12 million people worldwide had pirated "Expendables 3" since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
+
+That likely contributed to the action movie\'s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after "Captain America: The Winter Soldier" (7.31 million), "Divergent" (6.29 million) and "The Amazing Spider-Man 2" (5.88 million). Moreover, that\'s despite "Expendables 3" becoming available more than three weeks prior to the film\'s U.S. theatrical debut.
+
+String with a number followed by a single quote \'Expendables 3\' vestibulum in arcu mi.',
+
+ 'Pirates have voted on !q2!The Expendables 3!q2! with their clicks !emdash! and it turns out the Sylvester Stallone-starrer hasn!apos!t been astoundingly popular among digital thieves, relatively speaking.
+
+As of Sunday, 5.12 million people worldwide had pirated !q2!Expendables 3!q2! since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
+
+That likely contributed to the action movie!apos!s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after !q2!Captain America: The Winter Soldier!q2! (7.31 million), !q2!Divergent!q2! (6.29 million) and !q2!The Amazing Spider-Man 2!q2! (5.88 million). Moreover, that!apos!s despite !q2!Expendables 3!q2! becoming available more than three weeks prior to the film!apos!s U.S. theatrical debut.
+
+String with a number followed by a single quote !q1!Expendables 3!q1! vestibulum in arcu mi.',
+ ),
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>