Item8408: Macro parameter values cannot end in backslash

pencil
Priority: Normal
Current State: Closed
Released In:
Target Release: n/a
Applies To: Engine
Component:
Branches:
Reported By: MichaelTempest
Waiting For:
Last Change By: MichaelTempest
Foswiki does not parse macro parameters correctly if a parameter value ends in a backslash. Foswiki should treat \\ in a parameter value as \, especially if it is followed by a quote.

Example

For example:
%SEARCH{web="System" topic="VarC*" type="regex" search="." scope="topic" separator="\\" format="$topic"}%

Searched: .

Results from System web retrieved at 07:42 (GMT)

VarCALC
CALC add spreadsheet calculations to tables and outside tables The %CALC{"formula"}% macro is handled by the SpreadSheetPlugin. There are around 90 formulae, such...
\" format=
VarCALCULATE
CALCULATE add spreadsheet formulae calls using standard Macro evaluation order. The %CALCULATE{"formula"}% macro is handled by the SpreadSheetPlugin. There are ar...
\" format=
VarCOMMENT
COMMENT insert an edit box into the topic to easily add comments. Parameters * The following standard attributes are recognized Name Descriptio...
\" format=
VarCOVER
COVER current skin cover Extends the skin search path. For instance, if SKIN is set to catskin, bearskin, and COVER is set to ruskin, the skin search path becomes...
Number of topics: 4


In this example, the release branch ignores both the separator and the format parameters. Trunk does not see the format parameter, and it sees the separator parameter as \" format=

The cause

Foswiki::Attrs::new() contains the following code:


    $string =~ s/\\(["'])/$MARKER.sprintf("%.2u", ord($1))/ge
      ;    # escapes

Take 1: A simple fix

I think it should be:

    $string =~ s/\\(["'\\])/$MARKER.sprintf("%.2u", ord($1))/ge
      ;    # escapes

Possible breakage

The problem with this simple fix is that it could break exising pages. It would change the meaning of %FOO{"a\\b"}%. Without the fix, macro's handler sees a _DEFAULT parameter whose value is a\\b. The simple fix would change the value to a\b - note that there is one less backslash.

-- MichaelTempest - 21 Jan 2010

I cannot see a great loss in doing your fix.

Yes, there is a small possibility that it breaks an existing application where someone assumed the \\ was a double backslash. But that must be a very rare case.

Maybe others would want to comment

-- KennethLavrsen - 22 Jan 2010

write some unit tests for cases in which you think it might / should break and the unit test showing the bug, commit them, then fix your bug, and change any unit tests that need to be updated.

that way you've doccoed what has changed, and we have a few more unit tests smile

i agree with Kenneth - its not something many people will have done.

-- SvenDowideit - 22 Jan 2010

Confirmed breakage

distro:26ec8d15ef6a caused significant wiki app breakage. Let me try to explain. On a level 2 of standard escape like $dollarpercnt quotes tend to be escaped twice as well like in \\". Changeset 6152 changed that causing major incompatibilities for wiki apps. I haven't looked at what is being discussed here. For now I will revert the one-line change in Attrs.pm.

-- MichaelDaum - 29 Jan 2010

Workaround

Michael suggested separator="\" . For a search term, I could use "c:[\\]" instead of "c:\\"

There doesn't appear to be any way to fix this properly. I added unit tests to catch the breakage. I am closing this task.

-- MichaelTempest - 29 Jan 2010

 
Topic revision: r13 - 29 Jan 2010, MichaelTempest
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy