PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.7
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.7
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / guzzlehttp / psr7 / src / DiagnosticValue.php

DiagnosticValue.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.7, at vendor_prefixed/guzzlehttp/psr7/src/DiagnosticValue.php

51 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\GuzzleHttp\Psr7;
5
6 /**
7 * Escapes control characters and malformed UTF-8 for use in diagnostics.
8 */
9 final class DiagnosticValue
10 {
11 private function __construct()
12 {
13 }
14 /**
15 * Escapes C0, DEL, and C1 controls as uppercase `\xNN` sequences.
16 *
17 * ASCII bytes from 0x20 through 0x7E and valid UTF-8 characters outside
18 * those control ranges remain unchanged. If the input is malformed UTF-8 or
19 * PCRE cannot process it, every byte outside printable ASCII is escaped.
20 * Valid C1 characters are rendered as `\xNN` using their Unicode code
21 * points. During bytewise fallback, each original byte outside printable
22 * ASCII is rendered in the same form. The result is diagnostic text, not a
23 * reversible encoding.
24 *
25 * This does not encode values for HTML, JSON, shells, terminals, URLs, or
26 * protocol fields.
27 */
28 public static function escape(string $value) : string
29 {
30 $escaped = \preg_replace_callback('/[\\x{0000}-\\x{001F}\\x{007F}-\\x{009F}]/u', static function (array $matches) : string {
31 $character = $matches[0];
32 $codePoint = \strlen($character) === 1 ? \ord($character) : \ord($character[1]);
33 return \sprintf('\\x%02X', $codePoint);
34 }, $value);
35 return $escaped ?? self::escapeBytes($value);
36 }
37 private static function escapeBytes(string $value) : string
38 {
39 $escaped = '';
40 for ($offset = 0, $length = \strlen($value); $offset < $length; ++$offset) {
41 $byte = \ord($value[$offset]);
42 if ($byte >= 0x20 && $byte <= 0x7e) {
43 $escaped .= $value[$offset];
44 continue;
45 }
46 $escaped .= \sprintf('\\x%02X', $byte);
47 }
48 return $escaped;
49 }
50 }
51