PHP's preg_replace() with 'e' flag will (for whatever reason), add some slashes to output.

I've yet to determine if simply calling stripslashes() inside the preg_replace callback is appropriate.

Also, preg_replace with /e is deprecated and will stop existing in . Might be worth not using it.

Though, passing in the filter settings so they're available in the callback with preg_replace_callback would require a closure and therefore 5.3 or above. Seems like there should be a way to do it pre-5.3, but I'm not clever enough this late at night.

Comments

lotyrin’s picture

Okay, stripslashes() definitely is not the solution.

"Hello World\n" becomes \"Hello World\n\" (and NOT \"Hello World\\n\"), so after stripslashes is just "Hello Worldn"

God you gotta just love PHP sometimes.

If we can trust that it's only adding slashes to quotes, then replacing '\"' with '"' would work... but I don't see any documentation anywhere of this problem, so we can't even assume that the problem exists consistently between different versions of PHP and preg_replace...

Wonder if this is why the /e flag is going away. (Though it's more likely that it's because it doesn't account for closures/anonymous functions.)

lotyrin’s picture

Title: Extra slashes in output » Literal code isn't passed to pygmentize unmodified.

Hmm. looks like even if we sidestep preg_replace, escapeshellarg() only deals with quotes, so things like \n don't get changed to \\n.

Updating title to reflect that there are several obstacles here.

lotyrin’s picture

Okay, here's the solution with a closure.

I might be able to pull this off in a hacky way that doesn't need PHP 5.3, but this is the nice and working modern solution.

capynet’s picture

Status: Active » Closed (won't fix)

Hi, version 7.x-1.0-alpha1 will no more be supported. Soon we will moving ahead to 2.0 version.
Close this issue.