Git Product home page Git Product logo

Comments (43)

thunderer avatar thunderer commented on June 19, 2024

Hi @mitjaprelovsek, thanks for the kind words about my library. I'm happy to help and will investigate the issue. In the meantime, can you share a PHP script to reproduce the problem (paste it here or create a gist)? I understand that the text above works fine, the problem is when you paste it several times in a single document?

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

@mitjaprelovsek I wrote this script to reproduce the issue, it introduces your shortcode handlers (removed la-color and la-slider because they were not used) and then tries to process your text example 10 times. Unfortunately, it works correctly producing 10 times the same block of text with the same four elements in each line. Can you verify it on your side?

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

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

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

$handlers = new HandlerContainer();
$handlers->add('la-text', function(ShortcodeInterface $s) {
    $format = $s->getParameter('format');
    
    return $format 
        ? sprintf("<div class='la-text'><%s>%s</%s></div>", $format, urldecode($s->getContent()), $format) 
        : sprintf("<div class='la-text'>%s</div>", urldecode($s->getContent()));
});
$handlers->add('la-row', function(ShortcodeInterface $s) {
    return sprintf("<div class='la-row'>%s</div>", $s->getContent());
});
$handlers->add('la-button', function(ShortcodeInterface $s) {
    return sprintf("<button id='%s' onClick='sendCommand(\"%s\")'>%s</button>", $s->getParameter('id'), $s->getParameter('command'), $s->getParameter('label'));
});
$handlers->add('la-padding', function(ShortcodeInterface $s) {
    return sprintf("<div style='padding:%s'></div>", $s->getParameter('height'));
});
$handlers->add('la-column', function(ShortcodeInterface $s) {
    return sprintf("<div class='la-column' style='width:%s;'>%s</div>", $s->getParameter('width'), $s->getContent());
});

$text = '[la-row][la-column width="100%"][la-text format="h1"]Welcome![/la-text][la-text]This page allows you to send commands to LightAct.[/la-text][/la-column][/la-row]
[la-row]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[/la-row]

';
$text = implode('', array_pad([], 10, $text));
$processor = new Processor(new RegularParser(), $handlers);

echo "<div class='la-main'>".$processor->process($text)."</div>";

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Can you check if the text is not always cut after a certain length? Maybe something is cutting the resulting HTML code and the browser displays everything it got from your script and fixing the rest. Please put something like EOF at the end of the input string and check if it is still there after processing. Windows environment could be an issue, but we need first to verify if the library output is correct.

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Is your text encoded in UTF8? This may be an issue as I'm using a lot of mb_*() functions with UTF8 parameter inside Processor class. If your text is anything other (CP1250, ISO-8859-2, Latin1, etc.) that may indeed be a problem (you can try converting through iconv() or mb_convert_encoding()). I see that indeed the output is cut to a certain length but I'm unable to reproduce it on my Linux machine even with 100 repetitions. I will need to find a Windows PC somewhere to test it, maybe I have one on my laptop home. Do you have a Linux box somewhere to check if it works correctly there?

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

PHPStorm displays file encoding at the bottom right of the editor, I know that you can change it also in SublimeText or Notepad++. But there may be another solution - could you try running the script (with 10 repetitions or more) I sent you in the console? Is the returned HTML correct there?

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Hi, @mitjaprelovsek have you tried running that script in the console? Also does the Linux environment work correctly? Today I should be able to get a Windows box to test how it works, will tell you if I found any errors.

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Hi, I got my friend working on Windows 10 and PHP 7.1.7 to test the script I posted above. Unfortunately again, we couldn't reproduce your issue. Could you please tell me your Windows and PHP version? I don't think IIS is to be blamed here, I don't see how it could interfere. Do you have anything other that could help me? Have you also checked your script encoding? I'm running out of ideas a little, but I hope we'll work out what the problem is.

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

 avatar commented on June 19, 2024

Hello again,

I've checked the encoding in Dreamweaver and it actually is set to UTF-8.
2017-08-23 12_40_33-greenshot

Can I try anything else?

from shortcode.

 avatar commented on June 19, 2024

Can you ask your friend to send me a screenshot of his IIS settings perhaps?

I am also attaching my phpinfo;

phpInfo.pdf

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

We didn't do it under IIS, we did it on Windows with latest XAMPP in the console. Did you try it like that? I don't think IIS is interfering with the output since we saw that HTML is cut in the middle but the end is preserved. I suspect there may be issue with the calculation of place where shortcode should be replaced, but I'm unable to reproduce it with virtually any configuration I have tried so far (Windows/Linux, different PHP versions, various encodings, etc.). Could you try to write a failing test case that reproduces your issue on a smaller scale?

from shortcode.

 avatar commented on June 19, 2024

I am looking into using XAMPP instead of IIS at the moment.

What do you mean 'on a smaller scale' exactly? With shorter text?

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

I mean that you first wrote about discarding "nested" shortcodes, so maybe try to reproduce it by artificially nesting them in various configurations (in my script there were 1-1-2 and 1-4-2, ie. every parent contains at most this number of children). Existing tests (especially ParserTest and ProcessorTest) should give you an idea how to do it. Look at ProcessorTest::testBaseOffset(), substitute your input text and see what numbers are missing, maybe this will give us any hint what to look for.

from shortcode.

 avatar commented on June 19, 2024

Ok, will do that (and probably also change my server to XAMPP instead of IIS). It will have to wait until Monday though when I am back at the main computer.

Thanks for all your help so far Tomasz!

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

No problem, I'm always happy to help. I'm a little worried though - this library has a quite extensive test suite and you came with something I can't reproduce. :) By the way, did you run PHPUnit on the included tests? Is it all green, all ~280 tests?

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Clone the repository in a separate place (or enter its directory in vendor), enter its directory, run composer install and then php vendor/bin/phpunit.

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

@mitjaprelovsek Hi, any news on your end?

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

 avatar commented on June 19, 2024

Hello again,

I've had the time now to test it on another machine with Wamp server + php 7.0.10 installed. The results are the same, unfortunately.

This code:

$text = '[la-row][la-column width="100%"][la-text format="h1"]Welcome![/la-text][la-text]This page allows you to send commands to LightAct.[/la-text][/la-column][/la-row]
[la-row]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[la-column width="25%"][la-text format="h4"]Sample heading 3[/la-text][la-text]Sample text[/la-text][/la-column]
[/la-row]

';

$text = implode('', array_pad([], 2, $text));
$text.="EOF";
$processor = new Processor(new RegularParser(), $handlers);

echo $processor->process($text);

gives me this output:

screenshot 2017-08-27 13 44 00

As you can see, the output is cut.
I am going to start playing with the phpunit now.

from shortcode.

 avatar commented on June 19, 2024

Hello again:

I've tried to follow your steps in regards to testing php with php unit and on running the php vendor/bin/phpunit I got this result in cmd window:

screenshot 2017-08-27 13 51 25

And on trying to run ProcessorTest.php in browser I got:

screenshot 2017-08-27 13 51 14

The results when running ParserTest.php were more or less the same.

It seems there is something wrong with PHPUnit installation. Would you be able to provide any help with this?

Thanks a lot!

from shortcode.

 avatar commented on June 19, 2024

ok, I've managed to get PHPUnit working by following this advice and changing the ProcessorTest.php. However, I got 53 errors, most of which are in relation to a 'class not found'

Please see below:

24) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #0 ('[declare date]%year%.%month%....ay=26]', '2015.08.26')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

25) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #1 ('[declare sample]%param%[/decl...value]', '[invalid param=value]')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

26) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #2 ('[declare]%param%[/declare][in...value]', '[invalid param=value]')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

27) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #3 ('[url]http://kowalczyk.cc[/url]', '<a href="http://kowalczyk.cc"...cc</a>')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

28) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #4 ('[url="http://kowalczyk.cc"]Vi...[/url]', '<a href="http://kowalczyk.cc"...t!</a>')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

29) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #5 ('[email][email protected][/email]', '<a href="mailto:[email protected]</a>')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

30) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #6 ('[email="[email protected]"]...email]', '<a href="mailto:[email protected]!</a>')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

31) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #7 ('[email="[email protected]" /]', '<a href="mailto:[email protected]</a>')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

32) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #8 ('[b]text[/b]', '<b>text</b>')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

33) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #9 ('[bb]text[/bb]', '<b>text</b>')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

34) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #10 ('[json arg=val]value[/json]', '{"name":"json","parameters":{...:null}')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

35) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #11 ('[text arg=val]value[/text]', '[text arg=val]value[/text]')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

36) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #12 ('[null arg=val]value[/null]', '')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

37) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #13 ('[name /]', 'name')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

C:\wamp64\www\LA1interface\vendor\thunderer\shortcode\tests\ProcessorTest.php:160

38) Thunder\Shortcode\Tests\ProcessorTest::testBuiltInHandlers with data set #14 ('[content]cnt[/content]', 'cnt')
Error: Class 'Thunder\Shortcode\HandlerContainer\HandlerContainer' not found

First of all, why is there 'Thunder\Shortcode' etc instead of 'Thunderer\Shortcode', which is what I have as folder names?

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Hi, @mitjaprelovsek, I can't tell what is the exact issue here and I'm out of ideas, maybe we could setup a Skype/TeamViewer session to resolve the problem? It's a strange thing that the output from Shortcode is cut at an arbitrary point and nothing seems to suggest a solution. Does this problem always show with longer texts or is it only when shortcodes are nested? Please try running another script and tell me if the output is cut at any point (should display START, then number 1-2000, then STOP):

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

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

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

$handlers = new HandlerContainer();
$handlers->setDefault(function(ShortcodeInterface $s) {
    return '<'.$s->getName().'>';
});

$text = implode('', array_map(function($num) {
    return '['.$num.']';
}, range(1, 2000)));
$processor = new Processor(new RegularParser(), $handlers);

echo 'START '.$processor->process($text).' STOP'."\n";

As for your comments, I forgot that things are a little harder on Windows and running PHPUnit may not be as easy. I'd like to help but I haven't really used Windows for years, so maybe just search for a tutorial how to setup it on your machine. The error you receive for HandlerContainer not found means that the autoloader script is missing. Also thunderer is my nickname, and I use Thunder as a vendor namespace everywhere.

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Hi @mitjaprelovsek, I'm sad that you decided to switch libraries, can you help me with this one last time? Can you run the code I pasted in my comment above and/or change RegularParser to RegexParser? The RegularParser is specific to my library, every other library you will find uses regexes to extract shortcodes.

from shortcode.

 avatar commented on June 19, 2024

Hi @thunderer , Sure, happy to. So, when I ran your original suggestion (with regularparser) I got this:

2017-08-29 10_08_38-laweb_tomasztest php

When I ran the modified parser where I change both use Thunder\Shortcode\Parser\RegexParser; line and $processor = new Processor(new RegexParser(), $handlers); I got this

2017-08-29 10_14_05-laweb_tomasztest php

So in the end it looks alright, doesn't it?

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Can you try to use your original text example with RegexParser then? I would be very happy if you go back to Shortcode instead of the other library. I will chase the problem with RegularParser on my own. Thank you for your help!

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Also, the XDebug error with RegularParser is expected as you either need to disable the extension or increase xdebug.max_nesting_level setting. Having 2000 levels of nesting is not something you do every day, though. :)

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

@mitjaprelovsek Unfortunately, I need to close this issue as not reproducible. I tried virtually any kind of input or configuration to experience your problem on multiple setups I had access to, and every time Shortcode worked as expected.

If you can verify the issue using a debugger and point me in any direction where the code is at fault, please open a new issue and I will be happy to take it further from there.

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

Hi @mitjaprelovsek, I got other reports of Shortcode issues in Windows environment in #56 and #57 and this time I was able to find the issue - there was an older version of the library installed (v0.6.0) even though there was a correct version qualifier in composer.json.

I was able to reproduce your issue while using an older version. Indeed, the text is cut at some point, but that was already fixed and definitely should work on the latest v0.6.5. I would be very grateful if you could check it once more and verify that it works for you. Thanks!

from shortcode.

jenstornell avatar jenstornell commented on June 19, 2024

Is it too much work to update the readme file with composer 0.6.5 instead of 0.6 for Windows users like us?

from shortcode.

 avatar commented on June 19, 2024

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

@jenstornell I will do that. The problem is that ^0.6 should install 0.6.5 and we don't know why you got an older version instead.

@mitjaprelovsek I'm only asking for rerunning the test code on the latest Shortcode version and confirming that it works. A simple yes/no answer will suffice, and I'll sleep better if you do this. :)

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

@jenstornell I merged all PRs (#60, #61, #62, #63), could you please check that everything works on your side on dev-master before I'll tag v0.6.6?

from shortcode.

jenstornell avatar jenstornell commented on June 19, 2024

It works on my side, but I have a very simple test and it's for Kirby CMS mainly:

[hello]

Some text.

[greetings firstname="Peter" lastname="Parker'., åäö"]
    [hello] This is a tag inside a tag.
    Kirby *markdown* can be used inside a tag.
    Html can be <strong>used as well</strong>!
    Even Kirbytags like (email: [email protected]) works.
åäö,._"'
    []
[/greetings]

Some more text.

[field-data]

But everything works now.

from shortcode.

devnix avatar devnix commented on June 19, 2024

Hi @mitjaprelovsek, I got other reports of Shortcode issues in Windows environment in #56 and #57 and this time I was able to find the issue - there was an older version of the library installed (v0.6.0) even though there was a correct version qualifier in composer.json.

I was able to reproduce your issue while using an older version. Indeed, the text is cut at some point, but that was already fixed and definitely should work on the latest v0.6.5. I would be very grateful if you could check it once more and verify that it works for you. Thanks!

May it probably be because the composer.lock? Maybe he could run composer update :-D

from shortcode.

thunderer avatar thunderer commented on June 19, 2024

@lightact @jenstornell @devnix I just tagged v0.7.0 with lots of fixes and improvements (just to mention over 10x performance improvement and memory reduction in RegularParser). With merged #72 which also contains the fix to very similar issue #70, I'm closing this issue.

Thanks for using Shortcode!

from shortcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.