<!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>[13978] trunk: Have get_search_query() escape by default, like it'
 s echoing counterpart the_search_query().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13978">13978</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-04-03 23:38:38 +0000 (Sat, 03 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Have get_search_query() escape by default, like it's echoing counterpart the_search_query(). see <a href="http://trac.wordpress.org/ticket/12780">#12780</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditphp">trunk/wp-admin/edit.php</a></li>
<li><a href="#trunkwpadminuploadphp">trunk/wp-admin/upload.php</a></li>
<li><a href="#trunkwpincludesfeedatomcommentsphp">trunk/wp-includes/feed-atom-comments.php</a></li>
<li><a href="#trunkwpincludesgeneraltemplatephp">trunk/wp-includes/general-template.php</a></li>
<li><a href="#trunkwpincludeslinktemplatephp">trunk/wp-includes/link-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit.php (13977 => 13978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit.php        2010-04-03 23:33:52 UTC (rev 13977)
+++ trunk/wp-admin/edit.php        2010-04-03 23:38:38 UTC (rev 13978)
</span><span class="lines">@@ -167,7 +167,7 @@
</span><span class="cx"> &lt;?php screen_icon(); ?&gt;
</span><span class="cx"> &lt;h2&gt;&lt;?php echo esc_html( $title ); ?&gt; &lt;a href=&quot;&lt;?php echo $post_new_file ?&gt;&quot; class=&quot;button add-new-h2&quot;&gt;&lt;?php echo esc_html_x('Add New', 'post'); ?&gt;&lt;/a&gt; &lt;?php
</span><span class="cx"> if ( isset($_GET['s']) &amp;&amp; $_GET['s'] )
</span><del>-        printf( '&lt;span class=&quot;subtitle&quot;&gt;' . __('Search results for &amp;#8220;%s&amp;#8221;') . '&lt;/span&gt;', esc_html( get_search_query() ) ); ?&gt;
</del><ins>+        printf( '&lt;span class=&quot;subtitle&quot;&gt;' . __('Search results for &amp;#8220;%s&amp;#8221;') . '&lt;/span&gt;', get_search_query() ); ?&gt;
</ins><span class="cx"> &lt;/h2&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span></span></pre></div>
<a id="trunkwpadminuploadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/upload.php (13977 => 13978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/upload.php        2010-04-03 23:33:52 UTC (rev 13977)
+++ trunk/wp-admin/upload.php        2010-04-03 23:38:38 UTC (rev 13978)
</span><span class="lines">@@ -168,7 +168,7 @@
</span><span class="cx"> &lt;?php screen_icon(); ?&gt;
</span><span class="cx"> &lt;h2&gt;&lt;?php echo esc_html( $title ); ?&gt; &lt;a href=&quot;media-new.php&quot; class=&quot;button add-new-h2&quot;&gt;&lt;?php echo esc_html_x('Add New', 'file'); ?&gt;&lt;/a&gt; &lt;?php
</span><span class="cx"> if ( isset($_GET['s']) &amp;&amp; $_GET['s'] )
</span><del>-        printf( '&lt;span class=&quot;subtitle&quot;&gt;' . __('Search results for &amp;#8220;%s&amp;#8221;') . '&lt;/span&gt;', esc_html( get_search_query() ) ); ?&gt;
</del><ins>+        printf( '&lt;span class=&quot;subtitle&quot;&gt;' . __('Search results for &amp;#8220;%s&amp;#8221;') . '&lt;/span&gt;', get_search_query() ); ?&gt;
</ins><span class="cx"> &lt;/h2&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span></span></pre></div>
<a id="trunkwpincludesfeedatomcommentsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/feed-atom-comments.php (13977 => 13978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/feed-atom-comments.php        2010-04-03 23:33:52 UTC (rev 13977)
+++ trunk/wp-includes/feed-atom-comments.php        2010-04-03 23:38:38 UTC (rev 13978)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx">                 if ( is_singular() )
</span><span class="cx">                         printf(ent2ncr(__('Comments on %s')), get_the_title_rss());
</span><span class="cx">                 elseif ( is_search() )
</span><del>-                        printf(ent2ncr(__('Comments for %1$s searching on %2$s')), get_bloginfo_rss( 'name' ), esc_attr(get_search_query()));
</del><ins>+                        printf(ent2ncr(__('Comments for %1$s searching on %2$s')), get_bloginfo_rss( 'name' ), get_search_query() );
</ins><span class="cx">                 else
</span><span class="cx">                         printf(ent2ncr(__('Comments for %s')), get_bloginfo_rss( 'name' ) . get_wp_title_rss());
</span><span class="cx">         ?&gt;&lt;/title&gt;
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx">         &lt;link rel=&quot;self&quot; type=&quot;application/atom+xml&quot; href=&quot;&lt;?php echo get_post_comments_feed_link('', 'atom'); ?&gt;&quot; /&gt;
</span><span class="cx">         &lt;id&gt;&lt;?php echo get_post_comments_feed_link('', 'atom'); ?&gt;&lt;/id&gt;
</span><span class="cx"> &lt;?php } elseif(is_search()) { ?&gt;
</span><del>-        &lt;link rel=&quot;alternate&quot; type=&quot;&lt;?php bloginfo_rss('html_type'); ?&gt;&quot; href=&quot;&lt;?php echo home_url() . '?s=' . esc_attr(get_search_query()); ?&gt;&quot; /&gt;
</del><ins>+        &lt;link rel=&quot;alternate&quot; type=&quot;&lt;?php bloginfo_rss('html_type'); ?&gt;&quot; href=&quot;&lt;?php echo home_url() . '?s=' . get_search_query(); ?&gt;&quot; /&gt;
</ins><span class="cx">         &lt;link rel=&quot;self&quot; type=&quot;application/atom+xml&quot; href=&quot;&lt;?php echo get_search_comments_feed_link('', 'atom'); ?&gt;&quot; /&gt;
</span><span class="cx">         &lt;id&gt;&lt;?php echo get_search_comments_feed_link('', 'atom'); ?&gt;&lt;/id&gt;
</span><span class="cx"> &lt;?php } else { ?&gt;
</span></span></pre></div>
<a id="trunkwpincludesgeneraltemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/general-template.php (13977 => 13978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/general-template.php        2010-04-03 23:33:52 UTC (rev 13977)
+++ trunk/wp-includes/general-template.php        2010-04-03 23:38:38 UTC (rev 13978)
</span><span class="lines">@@ -156,7 +156,7 @@
</span><span class="cx"> 
</span><span class="cx">         $form = '&lt;form role=&quot;search&quot; method=&quot;get&quot; id=&quot;searchform&quot; action=&quot;' . home_url() . '/&quot; &gt;
</span><span class="cx">         &lt;div&gt;&lt;label class=&quot;screen-reader-text&quot; for=&quot;s&quot;&gt;' . __('Search for:') . '&lt;/label&gt;
</span><del>-        &lt;input type=&quot;text&quot; value=&quot;' . esc_attr(apply_filters('the_search_query', get_search_query())) . '&quot; name=&quot;s&quot; id=&quot;s&quot; /&gt;
</del><ins>+        &lt;input type=&quot;text&quot; value=&quot;' . get_search_query() . '&quot; name=&quot;s&quot; id=&quot;s&quot; /&gt;
</ins><span class="cx">         &lt;input type=&quot;submit&quot; id=&quot;searchsubmit&quot; value=&quot;'. esc_attr__('Search') .'&quot; /&gt;
</span><span class="cx">         &lt;/div&gt;
</span><span class="cx">         &lt;/form&gt;';
</span><span class="lines">@@ -1642,7 +1642,7 @@
</span><span class="cx">                 $title = esc_attr(sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ));
</span><span class="cx">                 $href = get_author_feed_link( $author_id );
</span><span class="cx">         } elseif ( is_search() ) {
</span><del>-                $title = esc_attr(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query() ));
</del><ins>+                $title = esc_attr(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) ));
</ins><span class="cx">                 $href = get_search_feed_link();
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1825,12 +1825,21 @@
</span><span class="cx"> /**
</span><span class="cx">  * Retrieve the contents of the search WordPress query variable.
</span><span class="cx">  *
</span><ins>+ * The search query string is passed through {@link esc_attr()}
+ * to ensure that it is safe for placing in an html attribute.
+ *
</ins><span class="cx">  * @since 2.3.0
</span><ins>+ * @uses esc_attr()
</ins><span class="cx">  *
</span><ins>+ * @param bool $escaped Whether the result is escaped. Default true.
+ *         Only use when you are later escaping it. Do not use unescaped.
</ins><span class="cx">  * @return string
</span><span class="cx">  */
</span><del>-function get_search_query() {
-        return apply_filters( 'get_search_query', get_query_var( 's' ) );
</del><ins>+function get_search_query( $escaped = true ) {
+        $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
+        if ( $escaped )
+                $query = esc_attr( $query );
+        return $query;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -1839,11 +1848,11 @@
</span><span class="cx">  * The search query string is passed through {@link esc_attr()}
</span><span class="cx">  * to ensure that it is safe for placing in an html attribute.
</span><span class="cx">  *
</span><del>- * @uses attr
</del><ins>+ * @uses esc_attr()
</ins><span class="cx">  * @since 2.1.0
</span><span class="cx">  */
</span><span class="cx"> function the_search_query() {
</span><del>-        echo esc_attr( apply_filters( 'the_search_query', get_search_query() ) );
</del><ins>+        echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludeslinktemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/link-template.php (13977 => 13978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/link-template.php        2010-04-03 23:33:52 UTC (rev 13977)
+++ trunk/wp-includes/link-template.php        2010-04-03 23:38:38 UTC (rev 13978)
</span><span class="lines">@@ -686,7 +686,7 @@
</span><span class="cx">         global $wp_rewrite;
</span><span class="cx"> 
</span><span class="cx">         if ( empty($query) )
</span><del>-                $search = get_search_query();
</del><ins>+                $search = get_search_query( false );
</ins><span class="cx">         else
</span><span class="cx">                 $search = stripslashes($query);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>