Skip to content

Comments

Fix parsing of component tags with underscores#39

Merged
ganyicz merged 1 commit intomainfrom
filip/fix-tag-parsing
Feb 19, 2026
Merged

Fix parsing of component tags with underscores#39
ganyicz merged 1 commit intomainfrom
filip/fix-tag-parsing

Conversation

@ganyicz
Copy link
Collaborator

@ganyicz ganyicz commented Feb 19, 2026

The scenario

Components with underscores in their tag names are not parsed correctly by Blaze:

<x-my_component />

The problem

Our tag name and slot name regexes don't match Laravel's ComponentTagCompiler.

Ours:

// tag name
'/^[a-zA-Z0-9-\.:]+/'
// slot name
'/^[a-zA-Z0-9-]+/'

Laravel's:

// tag name
'[\w\-\:\.]*'
// slot name
'\w+(?:-\w+)*'

\w includes underscores (and is Unicode-aware), [a-zA-Z0-9] doesn't.

The solution

Introduced LaravelRegex — a class for regex patterns sourced from Laravel's ComponentTagCompiler:

/**
 * ...every constant in this class MUST match the corresponding regex
 * in Laravel's source exactly. Do not modify these without first
 * verifying the change against Laravel...
 */
class LaravelRegex
{
    /**
     * @see ComponentTagCompiler::compileOpeningTags()     — x[-\:]([\w\-\:\.]*)
     * @see ComponentTagCompiler::compileSelfClosingTags() — x[-\:]([\w\-\:\.]*)
     * @see ComponentTagCompiler::compileClosingTags()     — x[-\:][\w\-\:\.]*
     */
    const TAG_NAME = '/^[\w\-\:\.]*/';
}
if (preg_match(LaravelRegex::TAG_NAME, $this->remaining(), $matches)) {
    return $matches[0];
}

This avoids having to test every permutation of valid tag and slot names — we're relying on Laravel's behavior directly.

Any future change requires confronting the Laravel source references.

@ganyicz ganyicz changed the title Fix tag parsing Fix parsing of component tags with underscores Feb 19, 2026
@ganyicz ganyicz merged commit 580096e into main Feb 19, 2026
6 checks passed
@ganyicz ganyicz deleted the filip/fix-tag-parsing branch February 19, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant