PluginProbe
WooCommerce / 11.1.0
WooCommerce v11.1.0
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / lib / packages / Symfony / Component / CssSelector / Parser / Handler / StringHandler.php
StringHandler.php
78 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Parser\Handler;
13
14 use Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Exception\InternalErrorException;
15 use Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Exception\SyntaxErrorException;
16 use Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Parser\Reader;
17 use Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Parser\Token;
18 use Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping;
19 use Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
20 use Automattic\WooCommerce\Vendor\Symfony\Component\CssSelector\Parser\TokenStream;
21
22 /**
23 * CSS selector comment handler.
24 *
25 * This component is a port of the Python cssselect library,
26 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
27 *
28 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
29 *
30 * @internal
31 */
32 class StringHandler implements HandlerInterface
33 {
34 private $patterns;
35 private $escaping;
36
37 public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
38 {
39 $this->patterns = $patterns;
40 $this->escaping = $escaping;
41 }
42
43 /**
44 * {@inheritdoc}
45 */
46 public function handle(Reader $reader, TokenStream $stream): bool
47 {
48 $quote = $reader->getSubstring(1);
49
50 if (!\in_array($quote, ["'", '"'])) {
51 return false;
52 }
53
54 $reader->moveForward(1);
55 $match = $reader->findPattern($this->patterns->getQuotedStringPattern($quote));
56
57 if (!$match) {
58 throw new InternalErrorException(sprintf('Should have found at least an empty match at %d.', $reader->getPosition()));
59 }
60
61 // check unclosed strings
62 if (\strlen($match[0]) === $reader->getRemainingLength()) {
63 throw SyntaxErrorException::unclosedString($reader->getPosition() - 1);
64 }
65
66 // check quotes pairs validity
67 if ($quote !== $reader->getSubstring(1, \strlen($match[0]))) {
68 throw SyntaxErrorException::unclosedString($reader->getPosition() - 1);
69 }
70
71 $string = $this->escaping->escapeUnicodeAndNewLine($match[0]);
72 $stream->push(new Token(Token::TYPE_STRING, $string, $reader->getPosition()));
73 $reader->moveForward(\strlen($match[0]) + 1);
74
75 return true;
76 }
77 }
78