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

Bug with shortcodes with long text replace #37

Closed
Jonatanmdez opened this issue Feb 25, 2016 · 4 comments
Closed

Bug with shortcodes with long text replace #37

Jonatanmdez opened this issue Feb 25, 2016 · 4 comments
Assignees
Labels
Milestone

Comments

@Jonatanmdez
Copy link

Hi,

I'm having a problem with this amazing library. I use the shortcodes for really big replaces (Tables, imgs, etc).

The code: http://pastebin.com/NGWtVa4x (I couldn't insert in github with format)

The output: http://pastebin.com/27dQxrcL

As you can see, only works fine in the first shortcode. The second only first line. And , if you append more shortcodes, ignore them.

What's going on? I'm using dev-master version in composer.

@thunderer
Copy link
Owner

Hi @Jonatanmdez, thanks for the kind words and reporting this issue. I was able to reproduce it in the much shorter code:

<?php
require_once __DIR__ . '/vendor/autoload.php';

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

$handlers = new HandlerContainer();
foreach(['keyword-ranking-evolution','keyword-ranking-status'] as $shortcode){
    $handlers->add($shortcode, function(ShortcodeInterface $s){
        return 'Inicio: Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    });
}

$processor = new Processor(new RegularParser(), $handlers);
echo $processor->process('[keyword-ranking-status] [keyword-ranking-status]');

This bug is related to shortcode replacement logic - if the length of the replacements is greater than the length of the input string then replacements are applied only up to the input string's length. I fixed this bug by recalculating text length after each replacement. You can see it in the latest master commit d1bfba4 . I'll tag v0.6.1 after Travis will confirm that master is green.

@thunderer thunderer self-assigned this Feb 25, 2016
@thunderer thunderer added the bug label Feb 25, 2016
@thunderer thunderer added this to the 0.6 milestone Feb 25, 2016
@Jonatanmdez
Copy link
Author

Wow!!Very fast!

Now is working perfect. Thanks !

@thunderer
Copy link
Owner

@Jonatanmdez master is green, v0.6.1 was tagged. Could you please check if it fixes your problem and close this issue?

@thunderer
Copy link
Owner

Woah, you're really fast too! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants