<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[15929] trunk/wp-includes: Introduce sanitize_title_for_query().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15929">15929</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-10-23 12:55:55 +0000 (Sat, 23 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce sanitize_title_for_query(). See <a href="http://trac.wordpress.org/ticket/9591">#9591</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesformattingphp">trunk/wp-includes/formatting.php</a></li>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
<li><a href="#trunkwpincludestaxonomyphp">trunk/wp-includes/taxonomy.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesformattingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/formatting.php (15928 => 15929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/formatting.php        2010-10-23 12:17:33 UTC (rev 15928)
+++ trunk/wp-includes/formatting.php        2010-10-23 12:55:55 UTC (rev 15929)
</span><span class="lines">@@ -628,6 +628,7 @@
</span><span class="cx">                 chr(197).chr(186) =&gt; 'z', chr(197).chr(187) =&gt; 'Z',
</span><span class="cx">                 chr(197).chr(188) =&gt; 'z', chr(197).chr(189) =&gt; 'Z',
</span><span class="cx">                 chr(197).chr(190) =&gt; 'z', chr(197).chr(191) =&gt; 's',
</span><ins>+                chr(200).chr(153) =&gt; 's', chr(200).chr(155) =&gt; 't',
</ins><span class="cx">                 // Euro Sign
</span><span class="cx">                 chr(226).chr(130).chr(172) =&gt; 'E',
</span><span class="cx">                 // GBP (Pound) Sign
</span><span class="lines">@@ -783,19 +784,27 @@
</span><span class="cx">  *
</span><span class="cx">  * @param string $title The string to be sanitized.
</span><span class="cx">  * @param string $fallback_title Optional. A title to use if $title is empty.
</span><ins>+ * @param string $context Optional. The operation for which the string is sanitized
</ins><span class="cx">  * @return string The sanitized string.
</span><span class="cx">  */
</span><del>-function sanitize_title($title, $fallback_title = '') {
</del><ins>+function sanitize_title($title, $fallback_title = '', $context = 'save') {
</ins><span class="cx">         $raw_title = $title;
</span><del>-        $title = strip_tags($title);
-        $title = apply_filters('sanitize_title', $title, $raw_title);
</del><span class="cx"> 
</span><ins>+        if ( 'save' == $context )
+                $title = remove_accents($title);
+
+        $title = apply_filters('sanitize_title', $title, $raw_title, $context);
+
</ins><span class="cx">         if ( '' === $title || false === $title )
</span><span class="cx">                 $title = $fallback_title;
</span><span class="cx"> 
</span><span class="cx">         return $title;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function sanitize_title_for_query($title) {
+        return sanitize_title($title, '', 'query');
+}
+
</ins><span class="cx"> /**
</span><span class="cx">  * Sanitizes title, replacing whitespace with dashes.
</span><span class="cx">  *
</span><span class="lines">@@ -816,7 +825,6 @@
</span><span class="cx">         // Restore octets.
</span><span class="cx">         $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
</span><span class="cx"> 
</span><del>-        $title = remove_accents($title);
</del><span class="cx">         if (seems_utf8($title)) {
</span><span class="cx">                 if (function_exists('mb_strtolower')) {
</span><span class="cx">                         $title = mb_strtolower($title, 'UTF-8');
</span></span></pre></div>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (15928 => 15929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2010-10-23 12:17:33 UTC (rev 15928)
+++ trunk/wp-includes/query.php        2010-10-23 12:55:55 UTC (rev 15929)
</span><span class="lines">@@ -1784,7 +1784,7 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( '' != $q['name'] ) {
</span><del>-                        $q['name'] = sanitize_title( $q['name'] );
</del><ins>+                        $q['name'] = sanitize_title_for_query( $q['name'] );
</ins><span class="cx">                         $where .= &quot; AND $wpdb-&gt;posts.post_name = '&quot; . $q['name'] . &quot;'&quot;;
</span><span class="cx">                 } elseif ( '' != $q['pagename'] ) {
</span><span class="cx">                         if ( isset($this-&gt;queried_object_id) ) {
</span><span class="lines">@@ -1812,7 +1812,7 @@
</span><span class="cx"> 
</span><span class="cx">                         $page_for_posts = get_option('page_for_posts');
</span><span class="cx">                         if  ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) {
</span><del>-                                $q['pagename'] = sanitize_title( $this-&gt;_qv_basename( $q['pagename'] ) );
</del><ins>+                                $q['pagename'] = sanitize_title_for_query( $this-&gt;_qv_basename( $q['pagename'] ) );
</ins><span class="cx">                                 $q['name'] = $q['pagename'];
</span><span class="cx">                                 $where .= &quot; AND ($wpdb-&gt;posts.ID = '$reqpage')&quot;;
</span><span class="cx">                                 $reqpage_obj = get_page($reqpage);
</span><span class="lines">@@ -1824,7 +1824,7 @@
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                 } elseif ( '' != $q['attachment'] ) {
</span><del>-                        $q['attachment'] = sanitize_title( $this-&gt;_qv_basename( $q['attachment'] ) );
</del><ins>+                        $q['attachment'] = sanitize_title_for_query( $this-&gt;_qv_basename( $q['attachment'] ) );
</ins><span class="cx">                         $q['name'] = $q['attachment'];
</span><span class="cx">                         $where .= &quot; AND $wpdb-&gt;posts.post_name = '&quot; . $q['attachment'] . &quot;'&quot;;
</span><span class="cx">                 }
</span><span class="lines">@@ -1957,7 +1957,7 @@
</span><span class="cx">                                         $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; // there was a trailling slash
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><del>-                        $q['author_name'] = sanitize_title( $q['author_name'] );
</del><ins>+                        $q['author_name'] = sanitize_title_for_query( $q['author_name'] );
</ins><span class="cx">                         $q['author'] = get_user_by('slug', $q['author_name']);
</span><span class="cx">                         if ( $q['author'] )
</span><span class="cx">                                 $q['author'] = $q['author']-&gt;ID;
</span></span></pre></div>
<a id="trunkwpincludestaxonomyphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/taxonomy.php (15928 => 15929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/taxonomy.php        2010-10-23 12:17:33 UTC (rev 15928)
+++ trunk/wp-includes/taxonomy.php        2010-10-23 12:55:55 UTC (rev 15929)
</span><span class="lines">@@ -534,7 +534,7 @@
</span><span class="cx">                 case 'slug':
</span><span class="cx">                 case 'name':
</span><span class="cx">                         foreach ( $terms as $i =&gt; $term ) {
</span><del>-                                $terms[$i] = sanitize_term_field('slug', $term, 0, $taxonomy, 'db');
</del><ins>+                                $terms[$i] = sanitize_title_for_query( $term );
</ins><span class="cx">                         }
</span><span class="cx">                         $terms = array_filter($terms);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>