Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape breadcrumb label #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Escape breadcrumb label #88

wants to merge 1 commit into from

Conversation

vseager
Copy link
Contributor

@vseager vseager commented Dec 20, 2024

Fixes #87

@wubinworks
Copy link

@vseager
This fix is not enough, there are 2 problems:

  • If you use addslashes, Mickey's Store will become Mickey\'s Store.
    I suggest add this method to Block.
/**
     * Escape JSON string
     *
     * @param string $str
     * @return string
     */
    public function escapeJsonString(string $str): string
    {
        return mb_substr(json_encode(
            $str,
            JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION
        ), 1, -1);
    }

And then

"name": "<?= $block->escapeJsonString($block->escapeHtml($variable)) ?>"

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.

[Bug] Invalid JSON if string contains " or \ in multiple phtml files
2 participants