<!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"> <?php screen_icon(); ?>
</span><span class="cx"> <h2><?php echo esc_html( $title ); ?> <a href="<?php echo $post_new_file ?>" class="button add-new-h2"><?php echo esc_html_x('Add New', 'post'); ?></a> <?php
</span><span class="cx"> if ( isset($_GET['s']) && $_GET['s'] )
</span><del>-        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?>
</del><ins>+        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
</ins><span class="cx"> </h2>
</span><span class="cx">
</span><span class="cx"> <?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"> <?php screen_icon(); ?>
</span><span class="cx"> <h2><?php echo esc_html( $title ); ?> <a href="media-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a> <?php
</span><span class="cx"> if ( isset($_GET['s']) && $_GET['s'] )
</span><del>-        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?>
</del><ins>+        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
</ins><span class="cx"> </h2>
</span><span class="cx">
</span><span class="cx"> <?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">         ?></title>
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx">         <link rel="self" type="application/atom+xml" href="<?php echo get_post_comments_feed_link('', 'atom'); ?>" />
</span><span class="cx">         <id><?php echo get_post_comments_feed_link('', 'atom'); ?></id>
</span><span class="cx"> <?php } elseif(is_search()) { ?>
</span><del>-        <link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php echo home_url() . '?s=' . esc_attr(get_search_query()); ?>" />
</del><ins>+        <link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php echo home_url() . '?s=' . get_search_query(); ?>" />
</ins><span class="cx">         <link rel="self" type="application/atom+xml" href="<?php echo get_search_comments_feed_link('', 'atom'); ?>" />
</span><span class="cx">         <id><?php echo get_search_comments_feed_link('', 'atom'); ?></id>
</span><span class="cx"> <?php } else { ?>
</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 = '<form role="search" method="get" id="searchform" action="' . home_url() . '/" >
</span><span class="cx">         <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
</span><del>-        <input type="text" value="' . esc_attr(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
</del><ins>+        <input type="text" value="' . get_search_query() . '" name="s" id="s" />
</ins><span class="cx">         <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
</span><span class="cx">         </div>
</span><span class="cx">         </form>';
</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>