comparison vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
1 <?php 1 <?php declare(strict_types=1);
2 2
3 namespace PhpParser\Node\Scalar; 3 namespace PhpParser\Node\Scalar;
4 4
5 use PhpParser\Error; 5 use PhpParser\Error;
6 use PhpParser\Node\Scalar; 6 use PhpParser\Node\Scalar;
14 const KIND_NOWDOC = 4; 14 const KIND_NOWDOC = 4;
15 15
16 /** @var string String value */ 16 /** @var string String value */
17 public $value; 17 public $value;
18 18
19 protected static $replacements = array( 19 protected static $replacements = [
20 '\\' => '\\', 20 '\\' => '\\',
21 '$' => '$', 21 '$' => '$',
22 'n' => "\n", 22 'n' => "\n",
23 'r' => "\r", 23 'r' => "\r",
24 't' => "\t", 24 't' => "\t",
25 'f' => "\f", 25 'f' => "\f",
26 'v' => "\v", 26 'v' => "\v",
27 'e' => "\x1B", 27 'e' => "\x1B",
28 ); 28 ];
29 29
30 /** 30 /**
31 * Constructs a string scalar node. 31 * Constructs a string scalar node.
32 * 32 *
33 * @param string $value Value of the string 33 * @param string $value Value of the string
34 * @param array $attributes Additional attributes 34 * @param array $attributes Additional attributes
35 */ 35 */
36 public function __construct($value, array $attributes = array()) { 36 public function __construct(string $value, array $attributes = []) {
37 parent::__construct($attributes); 37 parent::__construct($attributes);
38 $this->value = $value; 38 $this->value = $value;
39 } 39 }
40 40
41 public function getSubNodeNames() { 41 public function getSubNodeNames() : array {
42 return array('value'); 42 return ['value'];
43 } 43 }
44 44
45 /** 45 /**
46 * @internal 46 * @internal
47 * 47 *
50 * @param string $str String token content 50 * @param string $str String token content
51 * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes 51 * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
52 * 52 *
53 * @return string The parsed string 53 * @return string The parsed string
54 */ 54 */
55 public static function parse($str, $parseUnicodeEscape = true) { 55 public static function parse(string $str, bool $parseUnicodeEscape = true) : string {
56 $bLength = 0; 56 $bLength = 0;
57 if ('b' === $str[0] || 'B' === $str[0]) { 57 if ('b' === $str[0] || 'B' === $str[0]) {
58 $bLength = 1; 58 $bLength = 1;
59 } 59 }
60 60
61 if ('\'' === $str[$bLength]) { 61 if ('\'' === $str[$bLength]) {
62 return str_replace( 62 return str_replace(
63 array('\\\\', '\\\''), 63 ['\\\\', '\\\''],
64 array( '\\', '\''), 64 ['\\', '\''],
65 substr($str, $bLength + 1, -1) 65 substr($str, $bLength + 1, -1)
66 ); 66 );
67 } else { 67 } else {
68 return self::parseEscapeSequences( 68 return self::parseEscapeSequences(
69 substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape 69 substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape
80 * @param null|string $quote Quote type 80 * @param null|string $quote Quote type
81 * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes 81 * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
82 * 82 *
83 * @return string String with escape sequences parsed 83 * @return string String with escape sequences parsed
84 */ 84 */
85 public static function parseEscapeSequences($str, $quote, $parseUnicodeEscape = true) { 85 public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string {
86 if (null !== $quote) { 86 if (null !== $quote) {
87 $str = str_replace('\\' . $quote, $quote, $str); 87 $str = str_replace('\\' . $quote, $quote, $str);
88 } 88 }
89 89
90 $extra = ''; 90 $extra = '';
109 }, 109 },
110 $str 110 $str
111 ); 111 );
112 } 112 }
113 113
114 private static function codePointToUtf8($num) { 114 /**
115 * Converts a Unicode code point to its UTF-8 encoded representation.
116 *
117 * @param int $num Code point
118 *
119 * @return string UTF-8 representation of code point
120 */
121 private static function codePointToUtf8(int $num) : string {
115 if ($num <= 0x7F) { 122 if ($num <= 0x7F) {
116 return chr($num); 123 return chr($num);
117 } 124 }
118 if ($num <= 0x7FF) { 125 if ($num <= 0x7FF) {
119 return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); 126 return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80);
137 * @param string $str String token content 144 * @param string $str String token content
138 * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes 145 * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
139 * 146 *
140 * @return string Parsed string 147 * @return string Parsed string
141 */ 148 */
142 public static function parseDocString($startToken, $str, $parseUnicodeEscape = true) { 149 public static function parseDocString(string $startToken, string $str, bool $parseUnicodeEscape = true) : string {
143 // strip last newline (thanks tokenizer for sticking it into the string!) 150 // strip last newline (thanks tokenizer for sticking it into the string!)
144 $str = preg_replace('~(\r\n|\n|\r)\z~', '', $str); 151 $str = preg_replace('~(\r\n|\n|\r)\z~', '', $str);
145 152
146 // nowdoc string 153 // nowdoc string
147 if (false !== strpos($startToken, '\'')) { 154 if (false !== strpos($startToken, '\'')) {
148 return $str; 155 return $str;
149 } 156 }
150 157
151 return self::parseEscapeSequences($str, null, $parseUnicodeEscape); 158 return self::parseEscapeSequences($str, null, $parseUnicodeEscape);
152 } 159 }
160
161 public function getType() : string {
162 return 'Scalar_String';
163 }
153 } 164 }