We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 785
    • 2,113 Posts
    I do not understand why, but in search.class.inc.php command:
    if ($this->isPhp5) $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); 

    for me does not work, and works only if to change on:
    if ($this->isPhp5) {$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
    		$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');}

    that is when I repeat this command.
      Создание сайтов на MODx, поддержка сайтов, поисковая оптимизация, программирование, копирайтинг
      Статьи о MODx, регулярно новые публикации
      • 5811
      • 1,717 Posts
      with : AjaxSearch 1.8.1 - Php5.2.6 - MySql 5.0.51b-community-nt
      I have done the following test:
              if ($this->isPhp5) {
                $text0 = 'méri&';
                if ($this->dbg) $this->asDebug->dbgLog($text0,"text0 - 1");
                $text0 = html_entity_decode($text0, ENT_QUOTES, 'UTF-8');
                if ($this->dbg) $this->asDebug->dbgLog($text0,"text0 - 2");
                
                $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
              }
      And I find the correct results:
      [27-Oct-08 04:25:21]  text0 - 1 : méri&
      [27-Oct-08 04:25:21]  text0 - 2 : méri&

      Have you solved or understood your issue ?
        • 785
        • 2,113 Posts
        I have understood - function stripHtml incorrectly works.
        Example:
        echo htmlspecialchars(strip_tags("méri&"), ENT_QUOTES);
        Result:
        méri&
          Создание сайтов на MODx, поддержка сайтов, поисковая оптимизация, программирование, копирайтинг
          Статьи о MODx, регулярно новые публикации
          • 5811
          • 1,717 Posts
          Is this new version of the stripHtml function could solve your issue ?
          function stripHtml($text){
            // prevent js XSS and remove HTML tags
            $isPhp5 = (version_compare(phpversion(), "5.0.0", ">=")) ? true : false;
            
            if ($isPhp5) {
              $text = html_entity_decode($text,ENT_QUOTES,'UTF-8');
              $text = htmlspecialchars(strip_tags($text), ENT_COMPAT, 'UTF-8');
            }
            else {
              $text = html_entity_decode($text,ENT_QUOTES);
              $text = htmlspecialchars(strip_tags($text), ENT_COMPAT);
            }
            
            return $text;
          }
          I prefer to use ENT_COMPAT (rather than ENT_QUOTES) in the second statement, otherwise, the search of something like l’éducation doesn’t run
            • 785
            • 2,113 Posts
            Quote from: coroico at Oct 28, 2008, 10:19 AM

            new version of the stripHtml function
            Like correctly would work, but why in function it is not checked: utf8 or not (all php5 converting in utf8)?
              Создание сайтов на MODx, поддержка сайтов, поисковая оптимизация, программирование, копирайтинг
              Статьи о MODx, регулярно новые публикации
              • 5811
              • 1,717 Posts
              You are right, but after thought, the mess comes from the fact that I use stripHtml to strip both input search term and output results !

              So for the next release I suggest the following updates:
              1/ change the defaultStripInput to prevent js XSS by using htmlspecialChar and stripJsScript().
              - $pgCharset could be ISO8859-1, UTF-8, cp1251 and some others. With an unknown page charset, ISO8859-1 will be used.
              - we set double_encode (the last parameter of htmlspecialchars function) to false to avoid multiple encoding
              - I add the use of the stripJsScript to strip js tags
                function defaultStripInput($searchString, $pgCharset = 'UTF-8'){
              
                  if ($searchString !== ''){
                    // Remove escape characters
                    $searchString = stripslashes($searchString);
              
                    // Remove js tags
                    $searchString = stripJscripts($searchString);
                    
                    // Remove modx sensitive tags
                    $searchString = stripTags($searchString);
              
                    // Strip HTML tags
                    $searchString = stripHtml($searchString);
                  
                    // and finally prevent JS XSS
                    $searchString = htmlspecialchars($searchString, ENT_COMPAT, $pgCharset, False);
              
                  }  
                  return $searchString;
                }
              

              2/ come back to a simpler stripHtml function to strip output results
              function stripHtml($text){
                // remove HTML tags
                return strip_tags($text);
              }
                • 785
                • 2,113 Posts
                So like all is good.
                  Создание сайтов на MODx, поддержка сайтов, поисковая оптимизация, программирование, копирайтинг
                  Статьи о MODx, регулярно новые публикации