-
Notifications
You must be signed in to change notification settings - Fork 28
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
Skip processing handler if this is not a valid shortcode #26
Conversation
Weird it didn't pass travis checks, looks valid to me :) Anyway, something else is going on. Even with valid shortcodes that work in other pages, it's not working in this one page. so will investigate further. |
Ok, have narrowed down the corruption problem with valid shortcodes to this in my content before any of the shortcodes:
I'm guessing the |
@rhukster Hi, thanks for reporting the issue! I'd really like to help you, but first let me clarify some points you made here:
In order to fully debug this, I'd need the text that is causing problems for you and which parser you used (I saw |
I didn't take into account all the various nested situations that may arise, so my fix was probably a bit hasty. Also I switched to the I definitely feel like my markdown image code sample: |
@rhukster I'm glad that everything is correct now. I've tagged release I'd really want to take a look at the problem you had with All in all I'm very happy that you use Shortcode in GravCMS! If you have any ideas how to improve the library or any other problems with using it, let me know! I'm now working in my spare time on the better documentation, there is also events subsystem and bundled handlers waiting in line, you can see the code in the other branches in this repository. |
I actually have a test setup for you. I think you will find it interesting.. give me a few to package it up. |
Ok, so please clone https://github.com/rhukster/shortcode-test into your webroot somewhere and I have created a simple test to replicate the issues as closely as possible. Basically I am loading a markdown file, using
Grav is a flat-file CMS where speed is paramount. A typical Grav site renders every page within 20ms or so after cache, and certainly < 100ms without cache. So we really need the speed of the RegexParser without the corruption issues :) Hopefully this test repo will give you a good largish-real world example to do some performance optimizations. Cheers! |
Oh one last thing.. I noticed this in PHP 5.6 and 5.7, where as PHP 5.5 doesn't seem to cause the problems with the RegexParser at least in my test setup. |
Arrggg.. sorry for the rambling but i think i found the culprit. I had this text:
Looks harmless but I noticed that in PHP 5.5 the apostrophe showed as a special character in my test setup. But looked like a regular quote in PHP 5.6 and 7.0. So this was pasted in as an extended UTF-8 character. This appears to be throwing the regex out of whack (I tried WordpressParser and RegexParser with same results). Changing this to a regular |
After adding an |
@rhukster Thanks for the test repository, it's great! I already made some changes and shaved off several milliseconds. :) I'm happy that you resolved the issue with your Markdown code. Internal encoding is a great clue because I use BTW Could you tell me what your default |
I know i didn't make it very clear, but let me recount the situation: PHP 5.5 - Default internal encoding is PHP 5.6+ - Default internal encoding is already I forced the This is also set this way in Grav for consistency. Regarding platform. I'm running on Mac OS X 10.11.3. PHP 5.5, 5.6 and 7.0. I am able to run Apache, Nginx, Caddy server in parallel (different ports), with mod_php, and php-fpm, all exhibit the same behavior now irrespective of the PHP version or web server. |
BTW, in summary there are two issues currently outstanding:
Should I open up issues for each of these? |
@rhukster thanks for the clarification. I think I understand what is going on. I spent some time tinkering on the "small" example from your repo and Blackfire reported 54% improvement in Unfortunately "full" example is still unable to complete, but I know where the problem is: there are many unclosed shortcodes like I didn't have enough time to check the corruption problem in RegexParser yet, but I'll work on it as soon as possible. Opening separate issues for these problems is a good idea, especially given the excellent input you've provided here. Discussing isolated issues is much better than commenting on everything on closed PR. :) |
ok will do.. btw i have some ideas that would improve flexibility too.. i'll open up an issue to discuss that too. |
Probably already saw but I added some ideas to the ideas issue: #16 I think at this point we can communicate on those 3 open issue, and this one can remained closed, and RIP :) |
I was getting some very strange content corruption when I enabled my shortcode plugin that uses your fantastic little shortcode library. This was caused by my having some square bracketed content that did not match up with any of my defined shortcode handlers:
This
[title]
,[, alt]
and[, classes]
text is used in my documentation to display optional method params. However, it was corrupting that title to something like:I debugged this in the Shortcode library and discovered that you were first collecting all the potential shortcodes in the entire page (quite a lot for me), and then iterating over them. However, when you retrieved the handler for every shortcode, it would continue to try to process the shortcode even if the handler was null. This ultimately leads to all kinds of corruption of the end content.
Simply checking to see if this handler is null, and then continuing without doing any more processing ensures there is no corruption, and also speeds up the page parsing considerably.
FYI - I created a core shortcode plugin for Grav CMS, and a subsequent shortcode plugin that adds some UI specific shortcodes in case you are interested.