Decode a chunk of encoded text to be used as an attribute value

Decodes escaped literals and removes slashes and 0x1A characters

@param  string $str Encoded text
@return string      Decoded text
487684
public function decode($str)
	{
		if ($this->decodeHtmlEntities && strpos($str, '&') !== false)
		{
			$str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
		}
		$str = str_replace("\x1A", '', $str);

		if ($this->hasEscapedChars)
		{
			$str = strtr(
				$str,
				[
					"\x1B0" => '!', "\x1B1" => '"', "\x1B2" => "'", "\x1B3" => '(',
					"\x1B4" => ')', "\x1B5" => '*', "\x1B6" => '[', "\x1B7" => '\\',
					"\x1B8" => ']', "\x1B9" => '^', "\x1BA" => '_', "\x1BB" => '`',
					"\x1BC" => '~'
				]
			);
		}

		return $str;
	}
1062683
private function charPad($str)
    {
        $l = strlen($str)*8;     // # of bits from input string
        $str .= "\x80";          // append the "1" bit followed by 7 0's
        $k = (512 - (($l + 8 + 64) % 512)) / 8;   // # of 0 bytes to append
        $k += 4;    // PHP String's will never exceed (2^31)-1, so 1st 32bits of
                    // the 64-bit value representing $l can be all 0's
        for ($x = 0; $x < $k; $x++) {
            $str .= "\0";
        }
        // append the last 32-bits representing the # of bits from input string ($l)
        $str .= chr((($l >> 24) & 0xFF));
        $str .= chr((($l >> 16) & 0xFF));
        $str .= chr((($l >> 8) & 0xFF));
        $str .= chr(($l & 0xFF));
        return $str;
    }
186785
public function clean_string($str)
    {
        if ($this->is_ascii($str) === FALSE) {
            if (MB_ENABLED) {
                $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
            } elseif (ICONV_ENABLED) {
                $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
            }
        }

        return $str;
    }
650658
public static String decode(String str) {
    if (str!=null) {
      try {
        StringBuilder sb = new StringBuilder();
        for (int idx = str.toLowerCase().indexOf("%2f"); idx>=0; idx = str.toLowerCase().indexOf("%2f")) {
          sb.append(java.net.URLDecoder.decode(str.substring(0, idx),"UTF-8")).append(str.substring(idx, idx+3));
          str = str.substring(idx+3);
        }
        sb.append(java.net.URLDecoder.decode(str,"UTF-8"));
        str = sb.toString();
      } catch (Exception ex) {
      }
    }
    return str;
  }
79776
protected static String decodePercent(String str) {
        String decoded = null;
        try {
            decoded = URLDecoder.decode(str, "UTF8");
        } catch (UnsupportedEncodingException ignored) {
            NanoHTTPD.LOG.log(Level.WARNING, "Encoding not supported, ignored", ignored);
        }
        return decoded;
    }
652793
private function _out_string_encoding( &$str )
     {
        $rsc = $this->_source_result_charset();
        if( $rsc==1 ) {
            $rsstr = iconv(UCS2, 'utf-8', $str);
        }
        else if( $rsc==2 ) {
            $rsstr = iconv('utf-8', 'gb18030', iconv(UCS2, 'utf-8', $str) );
        }
        else{
            $rsstr = iconv('utf-8', 'big5', iconv(UCS2, 'utf-8', $str) );
        }
        return $rsstr;
     }
503587
function decode(str) {
  let off = 0;
  let olen = 0;
  const slen = str.length;
  const stra = [];
  const len = str.length;

  while (off < slen - 1 && olen < len) {
    let code = str.charCodeAt(off++);
    const c1 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
    code = str.charCodeAt(off++);
    const c2 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
    if (c1 === -1 || c2 === -1) break;
    let o = (c1 << 2) >>> 0;
    o |= (c2 & 0x30) >> 4;
    stra.push(String.fromCharCode(o));
    if (++olen >= len || off >= slen) break;
    code = str.charCodeAt(off++);
    const c3 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
    if (c3 === -1) break;
    o = ((c2 & 0x0f) << 4) >>> 0;
    o |= (c3 & 0x3c) >> 2;
    stra.push(String.fromCharCode(o));
    if (++olen >= len || off >= slen) break;
    code = str.charCodeAt(off++);
    const c4 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
    o = ((c3 & 0x03) << 6) >>> 0;
    o |= c4;
    stra.push(String.fromCharCode(o));
    ++olen;
  }
  const buffa = [];
  for (off = 0; off < olen; off++) buffa.push(stra[off].charCodeAt(0));
  return Buffer.from(buffa);
}
57475
private function sanitizeEscapedText($str)
    {
        $str = str_replace('&apos;', '&#39;', $str); // PHP's html_entity_decode doesn't seem to support that!

        /* <?php ?> blocks can't reliably work in attributes (due to escaping impossible in XML)
           so they have to be converted into special TALES expression
        */
        $types = version_compare(PHP_VERSION, '5.4.0') < 0 ? (ini_get('short_open_tag') ? 'php|=|' : 'php') : 'php|=';
        $str = preg_replace_callback("/<\?($types)(.*?)\?>/", array('self', 'convertPHPBlockToTALES'), $str);

        // corrects all non-entities and neutralizes potentially problematic CDATA end marker
        $str = strtr(preg_replace('/&(?!(?:#x?[a-f0-9]+|[a-z][a-z0-9]*);)/i', '&amp;', $str), array('<'=>'&lt;', ']]>'=>']]&gt;'));

        return $str;
    }
878779
public function encode_qp ($str) {
    $encoded = $this->fix_eol($str);
    if (substr($encoded, -2) != $this->LE)
        $encoded .= $this->LE;

    // Replace every high ascii, control and = characters
    $encoded = preg_replace_callback("/([\001-\010\013\014\016-\037\075\177-\377])/",
              array($this,'qp_replace_high_ascii'), $encoded);
    // Replace every spaces and tabs when it's the last character on a line
    $encoded = preg_replace_callback("/([\011\040])".$this->LE."/",
              array($this,'qp_replace_end_whitespace'), $encoded);

    // Maximum line length of 76 characters before CRLF (74 + space + '=')
    $encoded = $this->word_wrap($encoded, 74, true);

    return $encoded;
  }
741815
function clean_string($str)
	{
		if ($this->_is_ascii($str) === FALSE)
		{
			$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
		}

		return $str;
	}
328100
public function encrypt(string $str): string
    {
        return openssl_encrypt($str, self::CIPHER_METHOD, $this->key, 0, $this->getIv());
    }
1333308
function encodeToUTF8($str)
    {
        $encodage = mb_detect_encoding($str, "UTF-8, ISO-8859-1, ISO-8859-15, windows-1252", true);
        $str_utf8 = mb_convert_encoding($str, "UTF-8", $encodage);
        return $str_utf8;
    }
1279817
public static function getString(&$str)
    {
        $p = strpos($str, "\x00");
        if ($p === false) {
            return '';
        }
        $r   = static::binarySubstr($str, 0, $p);
        $str = static::binarySubstr($str, $p + 1);

        return $r;
    }
1084480
public static String decode(String str)
    {
        String ret = str;

        try
        {
            // De-obfuscate the string
            if(ret != null)
                ret = new String(Base64.decodeBase64(ret.getBytes()));
        }
        catch(NoClassDefFoundError e)
        {
            System.out.println("WARNING: unable to decode: "
                +e.getClass().getName()+": "+e.getMessage());
        }

        return ret;
    }
849315
public function decode($str)
    {
        $ret = mcrypt_decrypt($this->cipher, $this->key, $str, $this->mode, $this->iv);
        //去除补码
        if ($this->padding)
        {
            $ret =  self::PADDING_PKCS5 == $this->padding ? $this->stripPKCS5Padding($ret) : $this->stripPKCS7Padding($ret);
        }
        //是否使用BASE64编码
        if ($this->base64Encoding)
        {
            return base64_decode($ret);
        }
        else
        {
            return $ret;
        }
    }
273290
public function convertToUtf8($str) {
        if (mb_detect_encoding($str, "UTF-8, ISO-8859-1, GBK")!="UTF-8") {
            $str = utf8_encode($str);
        }
        $str = iconv('UTF-8', 'UTF-8//IGNORE', $str);
        return $str;
    }
1131999
public static function nailEncode(String $str) : String
    {
        $str = str_replace(array_keys(self::$nailChars), array_values(self::$nailChars), $str);

        return $str;
    }