the Perl syntax highlighter is mangling some perl code, for example, this line:

my(undef, undef, $ftype) = fileparse($file,qr{\..*});

using the perl syntax highlighter (which I guess does not work in this forum) the backslash in qr{\..*} is removed, and becomes qr{..*} which is no longer the correct code for the regexp.

Adding two backslashes overcomes the problem: qr{\\..*} but that means a person has to know they need to write bad code so it displays as good code, and there might be other problems that I have not spotted yet.

Regards,
Kevin

Recommended Answers

All 12 Replies

I will definitely look into this. However, you're the first person who has told me of a code snippet parsing problem, and the code snippet library has been active for quite awhile now. Can you duplicate this in all of the syntax languages? Does it always remove backslashes? Any help would be very appreciated. Thanks!

Can you please also link me to the snippet in question? Thanks!

the snippet in question is the only code snippet posted under perl. Here is the link:

http://www.daniweb.com/code/snippet535.html

It looks OK now because I added the second backslash as noted previously, otherwise the single backslash is removed from the display. This is a problem with the highlighter code, not the regular code tags.

Seems to be the same in the php syntax highlighter:

http://www.daniweb.com/code/snippet536.html

note there is no \ in this section of code: qr{..*}); but I did enter a backslash: qr{\..*});

(snippet536.html should be deleted after you take a look. )

Looks the same in Mozilla 1.5 and IE 6 so most likely not a browser problem.

this line parses a little oddly too in the same perl snippet:

use File::Basename;

but it's no big deal, the code is correct, just looks funny.

It looks like I need some more time to investigate this one. I don't understand why the backslash isn't displaying, and meanwhile it displays fine when you have one backlash in \n later on in the snippet.

I'm really stumped with the backslash problem. I cannot reproduce the error in other code snippets. The display of \ and / characters seem to work fine in other code snippets?? Do you have any idea why it wouldn't work in just this one spot, and yet \n works just fine in the same code snippet? Please note that DaniWeb was written in PHP and the \ character is the escaping character in PHP.

Member Avatar for iamthwee

Maybe there's a bug with that syntax highlighter you're using.

Tell me are you doing all the text formating straight to html or is it going through the reguluar bbcode tags, then via php and then to html?

Someone posts a code snippet and it is saved in raw format to the database. When someone views a code snippet, a check is done to see if there is a cached version of it within the post cache I wrote. If not, it is retrieved from the database where it goes through the syntax highlighter on the fly where it's wrapped in various <span> tags to color code it. Then, a serialized version of the pretty printed code snippet is saved to my post cache for future views.

I'm really stumped with the backslash problem. I cannot reproduce the error in other code snippets. The display of \ and / characters seem to work fine in other code snippets?? Do you have any idea why it wouldn't work in just this one spot, and yet \n works just fine in the same code snippet? Please note that DaniWeb was written in PHP and the \ character is the escaping character in PHP.

back-slashes are getting removed by the high-lighter unless they are inside single-quotes or inside double-quotes. You have to escape a back-slash with a back-slash if it's not inside single or double quoted strings (which is why \n works, it's inside of quotes) . It's probably because php is interpreting the back-slash as the escape character unless inside quotes.

The high-lighter needs to add the escaping back-slash automatically to back-slashes in code to avoid this unecessary interpolation of the escape character. Maybe vbulletin has some known recommendations about how to appropriately fix this small bug in the high-lighter.

None of this has anything to do with vBulletin, I'm afraid. It was all coded by me. I am rather suspicious that the problem lies in my code cache and not in the highlighter at all. However, thank you very much for pointing out it happens when the \ character is within quotes. That could help me debug my code which I haven't looked at in 5 months :)

None of this has anything to do with vBulletin, I'm afraid. It was all coded by me. I am rather suspicious that the problem lies in my code cache and not in the highlighter at all. However, thank you very much for pointing out it happens when the \ character is within quotes. That could help me debug my code which I haven't looked at in 5 months :)

OK, well, it's easy enough to just add the extra back-slash when entering code. Maybe you could post a note in the snippet forum letting potential contributors know about this "bug" and informing them of what to do.

I will definitely spend more time on it this week, and hopefully get it fixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.