PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / vendor / symfony / css-selector / Parser / Handler / StringHandler.php

StringHandler.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at vendor/symfony/css-selector/Parser/Handler/StringHandler.php

72 lines 2.3 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 Symfony\Component\CssSelector\Parser\Handler;
13
14 use Symfony\Component\CssSelector\Exception\InternalErrorException;
15 use Symfony\Component\CssSelector\Exception\SyntaxErrorException;
16 use Symfony\Component\CssSelector\Parser\Reader;
17 use Symfony\Component\CssSelector\Parser\Token;
18 use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping;
19 use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
20 use 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 public function __construct(
35 private TokenizerPatterns $patterns,
36 private TokenizerEscaping $escaping,
37 ) {
38 }
39
40 public function handle(Reader $reader, TokenStream $stream): bool
41 {
42 $quote = $reader->getSubstring(1);
43
44 if (!\in_array($quote, ["'", '"'], true)) {
45 return false;
46 }
47
48 $reader->moveForward(1);
49 $match = $reader->findPattern($this->patterns->getQuotedStringPattern($quote));
50
51 if (!$match) {
52 throw new InternalErrorException(\sprintf('Should have found at least an empty match at %d.', $reader->getPosition()));
53 }
54
55 // check unclosed strings
56 if (\strlen($match[0]) === $reader->getRemainingLength()) {
57 throw SyntaxErrorException::unclosedString($reader->getPosition() - 1);
58 }
59
60 // check quotes pairs validity
61 if ($quote !== $reader->getSubstring(1, \strlen($match[0]))) {
62 throw SyntaxErrorException::unclosedString($reader->getPosition() - 1);
63 }
64
65 $string = $this->escaping->escapeUnicodeAndNewLine($match[0]);
66 $stream->push(new Token(Token::TYPE_STRING, $string, $reader->getPosition()));
67 $reader->moveForward(\strlen($match[0]) + 1);
68
69 return true;
70 }
71 }
72