Browse Source

! missing global in SplitTopics.php
! improved strpos checking in Class-Package.php
! Added missing token in managelanguage form
! removed debug statement e.g Doh!
! added htmlspecialchar encoding to search words for bug [4539], needs more testing

Spuds 12 years ago
parent
commit
f8d5075a85

+ 2 - 2
Sources/Class-Package.php

@@ -813,7 +813,7 @@ class ftp_connection
 		$time = time();
 		do
 			$this->last_message = fgets($this->connection, 1024);
-		while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ') !== 3) && time() - $time < 5);
+		while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5);
 
 		// Was the desired response returned?
 		return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
@@ -830,7 +830,7 @@ class ftp_connection
 		$time = time();
 		do
 			$response = fgets($this->connection, 1024);
-		while (strpos($response, ' ') !== 3 && time() - $time < 5);
+		while (strpos($response, ' ', 3) !== 3 && time() - $time < 5);
 
 		// If it's not 227, we weren't given an IP and port, which means it failed.
 		if (strpos($response, '227 ') !== 0)

+ 0 - 1
Sources/Load.php

@@ -1371,7 +1371,6 @@ function isBrowser($browser)
 		}
 
 		log_error('Old browser support' . $function, 'debug', $file, $line);
-		var_dump($browser);die;
 	}
 
 	// Don't know any browser!

+ 25 - 19
Sources/Search.php

@@ -27,13 +27,12 @@ $GLOBALS['search_versions'] = array(
 /**
  * Ask the user what they want to search for.
  * What it does:
- * * shows the screen to search forum posts (action=search), and uses the
- *   simple version if the simpleSearch setting is enabled.
- * * uses the main sub template of the Search template.
- * * uses the Search language file.
- * * requires the search_posts permission.
- * * decodes and loads search parameters given in the URL (if any).
- * * the form redirects to index.php?action=search2.
+ * - shows the screen to search forum posts (action=search), and uses the simple version if the simpleSearch setting is enabled.
+ * - uses the main sub template of the Search template.
+ * - uses the Search language file.
+ * - requires the search_posts permission.
+ * - decodes and loads search parameters given in the URL (if any).
+ * - the form redirects to index.php?action=search2.
  */
 function PlushSearch1()
 {
@@ -234,13 +233,12 @@ function PlushSearch1()
 /**
  * Gather the results and show them.
  * What it does:
- * * checks user input and searches the messages table for messages
- *   matching the query.
- * * requires the search_posts permission.
- * * uses the results sub template of the Search template.
- * * uses the Search language file.
- * * stores the results into the search cache.
- * * show the results of the search query.
+ * - checks user input and searches the messages table for messages matching the query.
+ * - requires the search_posts permission.
+ * - uses the results sub template of the Search template.
+ * - uses the Search language file.
+ * - stores the results into the search cache.
+ * - show the results of the search query.
  */
 function PlushSearch2()
 {
@@ -572,8 +570,9 @@ function PlushSearch2()
 
 	// *** Parse the search query
 
-	// Unfortunately, searching for words like this is going to be slow, so we're blacklisting them.
-	/**
+	/*
+	 * Unfortunately, searching for words like this is going to be slow, so we're blacklisting them.
+	 *
 	 * @todo Setting to add more here?
 	 * @todo Maybe only blacklist if they are the only word, or "any" is used?
 	 */
@@ -616,8 +615,9 @@ function PlushSearch2()
 	$phraseArray = $matches[2];
 
 	// Remove the phrase parts and extract the words.
-	$wordArray = explode(' ', preg_replace('~(?:^|\s)(?:[-]?)"(?:[^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']));
-
+	$wordArray = preg_replace('~(?:^|\s)(?:[-]?)"(?:[^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']);
+	$wordArray = explode(' ',  $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES));
+	
 	// A minus sign in front of a word excludes the word.... so...
 	$excludedWords = array();
 	$excludedIndexWords = array();
@@ -626,21 +626,25 @@ function PlushSearch2()
 
 	// .. first, we check for things like -"some words", but not "-some words".
 	foreach ($matches[1] as $index => $word)
+	{
 		if ($word === '-')
 		{
 			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
 				$excludedWords[] = $word;
 			unset($phraseArray[$index]);
 		}
+		}
 
 	// Now we look for -test, etc.... normaller.
 	foreach ($wordArray as $index => $word)
+	{
 		if (strpos(trim($word), '-') === 0)
 		{
 			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
 				$excludedWords[] = $word;
 			unset($wordArray[$index]);
 		}
+	}
 
 	// The remaining words and phrases are all included.
 	$searchArray = array_merge($phraseArray, $wordArray);
@@ -1891,13 +1895,14 @@ function prepareSearchContext($reset = false)
 				$force_partial_word = false;
 				foreach ($context['key_words'] as $keyword)
 				{
+					$keyword = un_htmlspecialchars($keyword);
 					$keyword = preg_replace('~&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});~e', '$GLOBALS[\'smcFunc\'][\'entity_fix\'](\'\\1\')', strtr($keyword, array('\\\'' => '\'', '&' => '&amp;')));
 
 					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0)
 						$force_partial_word = true;
 					$matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|';
 				}
-				$matchString = substr($matchString, 0, -1);
+				$matchString = un_htmlspecialchars(substr($matchString, 0, -1));
 
 				$message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br />' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
 
@@ -2049,6 +2054,7 @@ function prepareSearchContext($reset = false)
 	foreach ($context['key_words'] as $query)
 	{
 		// Fix the international characters in the keyword too.
+		$query = un_htmlspecialchars($query);
 		$query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\''));
 
 		$body_highlighted = preg_replace('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/ie' . ($context['utf8'] ? 'u' : ''), "'\$2' == '\$1' ? stripslashes('\$1') : '<strong class=\"highlight\">\$1</strong>'", $body_highlighted);

+ 1 - 1
Sources/SplitTopics.php

@@ -495,7 +495,7 @@ function SplitSelectionExecute()
  */
 function splitTopic($split1_ID_TOPIC, $splitMessages, $new_subject)
 {
-	global $user_info, $topic, $board, $modSettings, $smcFunc, $txt;
+	global $user_info, $topic, $board, $modSettings, $smcFunc, $txt, $sourcedir;
 
 	// Nothing to split?
 	if (empty($splitMessages))

+ 1 - 0
Themes/default/ManageLanguages.template.php

@@ -195,6 +195,7 @@ function template_download_language()
 	echo '
 			<div class="righttext padding">
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="hidden" name="', $context['admin-dlang_token_var'], '" value="', $context['admin-dlang_token'], '" />
 				<input type="submit" name="do_install" value="', $txt['add_language_smf_install'], '" class="button_submit" />
 			</div>
 		</form>