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

Method getParameter returns value with quotes #76

Closed
drmzio opened this issue Feb 13, 2019 · 4 comments
Closed

Method getParameter returns value with quotes #76

drmzio opened this issue Feb 13, 2019 · 4 comments

Comments

@drmzio
Copy link

drmzio commented Feb 13, 2019

Parameter values using double quotes get passed back with double quotes when using getParameter. Maybe there's a way to modify this configuration to strip double quotes?

Environment

  • PHP v7.2
  • Shortcode v0.6.5
$handlers = new HandlerContainer();
$handlers->add('hello', function (ShortcodeInterface $s) {
    return sprintf('Hello, %s', $s->getParameter('name'));
});
$processor = new Processor(new WordpressParser(), $handlers);
return $processor->process($input);

This example shows two of the same shortcodes: one with double quotes for the parameter value and one without.

@thunderer
Copy link
Owner

Hi @drmzio, you're using WordpressParser which works exactly like WordPress. As noted in the class header, it is meant only as a compatibility layer if you need exactly the same behavior. Did anything change in WordPress that would require an update to this parser?

I recommend you to try the latest library version v0.7.1 with RegularParser. Does it work correctly for your use case?

@thunderer
Copy link
Owner

@drmzio By the way, I tested all parsers with the latest version of the library using PHP 7.2, and none of them result in the reported behavior. Could you please tell me what is the output of this code in your environment?

<?php
declare(strict_types=1);
namespace X;

use Thunder\Shortcode\HandlerContainer\HandlerContainer;
use Thunder\Shortcode\Parser\RegexParser;
use Thunder\Shortcode\Parser\RegularParser;
use Thunder\Shortcode\Parser\WordpressParser;
use Thunder\Shortcode\Processor\Processor;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;

require __DIR__.'/vendor/autoload.php';

$handlers = new HandlerContainer();
$handlers->add('hello', function (ShortcodeInterface $s) {
    return sprintf('Hello, %s', $s->getParameter('name'));
});

$input = '[hello name="Daniel"] [hello name=John]';
echo (new Processor(new RegexParser(), $handlers))->process($input)."\n";
echo (new Processor(new RegularParser(), $handlers))->process($input)."\n";
echo (new Processor(new WordpressParser(), $handlers))->process($input)."\n";

@drmzio
Copy link
Author

drmzio commented Feb 13, 2019

@thunderer Trying out the code above outputs:

Hello, Daniel Hello, John
Hello, Daniel Hello, John
Hello, Daniel Hello, John

So after further inspection, found out that the Markdown editor was the one escaping quotes. Since this issue isn't related to Shortcode itself, I'm closing this. Thanks for the help!

@drmzio drmzio closed this as completed Feb 13, 2019
@thunderer
Copy link
Owner

No problem, I'm happy that it works for you, @drmzio!

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

No branches or pull requests

2 participants