You are here: Foswiki>Tasks Web>Item2518 (14 Jun 2015, GeorgeClark)Edit Attach

Item2518: ENCODE type=quotes broken

pencil
Priority: Normal
Current State: No Action Required
Released In: n/a
Target Release: n/a
Applies To: Engine
Component:
Branches:
Reported By: HolgerHain
Waiting For:
Last Change By: GeorgeClark

Description

I wanted to use a conditional output of an icon with the IF macro. Because the ICON macro outputs a string containing double quotes these need to be escaped. Otherwise it will break my IF. So the solution I thought of is to use the ENCODE macro with type=quotes. This works very well with normal text, as well when I type in some html code.

The problem is it does not work when I use a macro as a string such as:
%ENCODE{"%ICON{led-green}%" type="quotes"}%

This outputs %3cimg%20width%3d%2216

Why are the html entities encoded and not just the double quotes???

-- HolgerHain - 21 Dec 2009

Key Problem

I did some more testing and think I got the real problem behind.

ICON outputs something like <img width="16" alt="..." ...

ENCODE now finds something like "<img width="16" alt="..." and thinks alt="..." is another parameter and the string ends after width="16". But this parameter is unknown so the encoding is set to default and the remaining string is discarded.

Possible Solutions

  • change qoutes for input string from double quotes to single quotes
    • This might cause some other problems
  • treat all "parameters" which are not type="..." as part of the string
  • move the type parameter to the beginning and treat all what is between the next double quote and the final double quote before }% as the string

I am just wondering why nobody reported this problem before, because for some applications there is no possible workaround!

-- HolgerHain - 21 Dec 2009

I tried to reproduce this and one thing I noticed was that my ICON returns single quotes and not double.

I guess this depends on the CGI version.

If we just set some variable

  • Set MYVAR = Hej"Ho

and then do %ENCODE{"%MYVAR%" type="quotes"}%

we get

Hej\"Ho

which does not indicate that ENCODE stops at the double quote it gets as input.

We can also try the ICON case

led-green

which gives same result as you get on foswiki.org but different on my home server - probably because of CGI version.

I do not see this as a release blocker. It must be a very old problem in ENCODE. But even a normal bug is worth fixing - if we can define a proper spec for it. It seems the spec as such can be a bit tricky for this ENCODE feature.

Trying with some hardcoded example

  • Set SOMEVAR = "Hallo" alt="trulu"

%22Hallo

Confirms your idea that the alt= is seen as an option for ENCODE.

  • Set SOMEVAR2 = 'Hallo' alt='trulu'

'Hallo' alt='trulu'

Single quotes works

  • Set SOMEVAR3 = 'Hal"lo' alt='trulu'

'Hal\"lo' alt='trulu'

And a double quote inside does not stop the string

My guess is that we need to look at ENCODE and have it interpret everything until it meets a "\s+type="quotes"

-- KennethLavrsen - 22 Dec 2009

Just looked at the code.

We cannot easily change a regex as the code for ENCODE is called once the standard interpreter has split the inputs in _DEFAULT and attributes. And changing the standard parsing of all macros is dangerous and should not be fixed through as an urgent bug.

We need to define a work around for Holger and keep this for 1.1 scope non urgent.

We may in fact need to consider an alternative syntax for ENCODE for the type="quotes" case.

-- KennethLavrsen - 22 Dec 2009

For my current problem I found a workaround using a $dollardollarpercnt syntax. But a normal user who tries to create a search which outputs yes/no values more visibly via green/red images may be very confused by something like this.

So I can agree to set it to non urgent, but anyway this problem should be solved.

Is it possible to create some kind of new macro just for the case ENCODE type="quotes" which does not use the standard interpreter and don´t change anything (except for the documentation) of the ENCODE?

With this single qouted html-tags:
I would prefere these (because of escaping reasons wink ). Is there some kind of documentation when foswiki will output single qouted tags and when double qouted ones? Changing this generally in engine is surely a lot of work (so I do not suggest to do this).

-- HolgerHain - 23 Dec 2009

Setting this to No Action. ICON macro can now select the quote type to use, and foswiki is attempting to standardize on single-quotes in HTML, double quotes in %MACROS.

-- Main.GeorgeClark - 14 Jun 2015 - 03:35

ItemTemplate edit

Summary ENCODE type=quotes broken
ReportedBy HolgerHain
Codebase 1.0.7
SVN Range Foswiki-1.0.7, Sun, 20 Sep 2009, build 5061
AppliesTo Engine
Component
Priority Normal
CurrentState No Action Required
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn n/a
CheckinsOnBranches
trunkCheckins
masterCheckins
ItemBranchCheckins
Release01x01Checkins
Topic revision: r6 - 14 Jun 2015, GeorgeClark
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