• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / texy / 44949415842

21 Nov 2026 08:56PM UTC coverage: 97.174% (+0.01%) from 97.162%
44949415842

push

github

dg
ElementDecorator, HtmlSanitizePass: a numeric class or style name no longer throws TypeError

A class such as .[start 5] is stored as an array key, which PHP turns into an
int, and the policy checks that take a string threw on it.

681d1c05-f259-441d-877e-829884510010

7 of 7 new or added lines in 2 files covered. (100.0%)

34 existing lines in 6 files now uncovered.

3886 of 3999 relevant lines covered (97.17%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.0
/src/Modules/DirectiveModule.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Texy! (https://texy.deegee.dev)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Texy\Modules;
9

10
use Texy;
11
use Texy\Nodes\DirectiveNode;
12
use Texy\Parsing\ParseContext;
13
use Texy\{Range, Syntax};
14
use function strlen;
15

16

17
/**
18
 * Processes {{macro}} script commands.
19
 */
20
final class DirectiveModule extends Texy\Module
21
{
22
        public function __construct(
1 ✔
23
                private Texy\Config $config,
24
        ) {
25
        }
1 ✔
26

27

28
        public function register(Texy\Parsing\Engine $engine): void
29
        {
30
                $engine->addInline(
1 ✔
31
                        Syntax::Directive,
1 ✔
32
                        '~
1 ✔
33
                                \{\{
34
                                ( }?+ (?: [^}]++ | } (?! } ) )*+ )  # content up to the first }} (1)
35
                                }}
36
                        ~x',
37
                        $this->parse(...),
1 ✔
38
                );
39
        }
1 ✔
40

41

42
        /**
43
         * Parses {{macro}}.
44
         * @param  array{string, string}  $matches
45
         * @param  array{int, int}  $offsets
46
         */
47
        public function parse(ParseContext $context, array $matches, array $offsets): ?DirectiveNode
48
        {
49
                return trim($matches[1]) === ''
1 ✔
UNCOV
50
                        ? null
×
51
                        : new DirectiveNode($matches[1], new Range($offsets[0], strlen($matches[0])));
1 ✔
52
        }
53

54

55
        /**
56
         * Consumes {{texy: ...}} into DocumentNode::$meta and hands the rest to the directive
57
         * handler. Runs as the first pass, so the handler may still change configuration the
58
         * later ones depend on. A handled directive is removed unless the handler returns
59
         * a replacement.
60
         */
61
        public function processDirectives(Texy\Nodes\DocumentNode $doc): void
62
        {
63
                (new Texy\NodeTraverser)->traverse($doc, function (Texy\Node $node) use ($doc): Texy\Node|Texy\TraverseAction|null {
1 ✔
64
                        if (!$node instanceof DirectiveNode) {
1 ✔
65
                                return null;
1 ✔
66
                        }
67

68
                        if ($node->name === 'texy' && $node->args) {
1 ✔
69
                                foreach ($node->args as $arg) {
1 ✔
70
                                        $doc->meta[$arg] = true;
1 ✔
71
                                }
72
                                return Texy\TraverseAction::Remove;
1 ✔
73
                        }
74

75
                        $handler = $this->config->directiveHandler;
1 ✔
76
                        if ($handler === null) {
1 ✔
77
                                return null;
1 ✔
78
                        }
79

80
                        $result = $handler($node);
1 ✔
81
                        return $result instanceof Texy\Node ? $result : Texy\TraverseAction::Remove;
1 ✔
82
                });
1 ✔
83
        }
1 ✔
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc