Edgewall Software

Opened 9 years ago

Last modified 9 years ago

#12023 closed defect

[wiki] wikiprocessor fails to properly render tag attributes with dashes hyphens eg. "data-collapse" — at Version 4

Reported by: lkraav <leho@…> Owned by: Jun Omae
Priority: normal Milestone: 1.0.6
Component: wiki system Version: 0.12
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Allow hyphen characters in parameter name of wiki processor.

API Changes:
Internal Changes:

Description

How to reproduce:

  • [wiki] render_unsafe_content = true
  • edit whatever, type {{{#!div data-collapse=""
  • observe dom changes in inspector

Result:

<div collapse="">

Expected:

<div data-collapse="">

Is this a Genshi bug or some Trac downstream configuration?

PS how do I add to safe_attrs list, so I could enable data-collapse or whatever without enabling full blown render_unsafe_content?

Change History (4)

comment:1 by lkraav <leho@…>, 9 years ago

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes this data-* is a standardized attribute class, so should be handled accordingly for sure

comment:2 by lkraav <leho@…>, 9 years ago

Version: 1.1.31.1dev

Not 100% if I'm seeing this correctly but

{{{#!div data_collapse=""
}}}

so underscore seems to get converted to hyphen data-collapse. I'm confused but I'll take it for time being.

Last edited 9 years ago by Jun Omae (previous) (diff)

comment:3 by Jun Omae, 9 years ago

Component: renderingwiki system
Milestone: 1.0.6
Owner: set to Jun Omae
Status: newassigned
Version: 1.1dev0.12

Currently, processor's parameter name disallows hyphen characters.

>>> from trac.wiki.parser import parse_processor_args
>>> parse_processor_args('data-name="1"')
{'name': '1'}   # ==> should be {'data-name': '1'} or {}

Also, the parser for processor's parameters has a defect.

  • trac/wiki/parser.py

    diff --git a/trac/wiki/parser.py b/trac/wiki/parser.py
    index 13efd15..bb07f7c 100644
    a b class WikiParser(Component):  
    6262    XML_NAME = r"[\w:](?<!\d)[\w:.-]*?" # See http://www.w3.org/TR/REC-xml/#id
    6363
    6464    PROCESSOR = r"(\s*)#\!([\w+-][\w+-/]*)"
    65     PROCESSOR_PARAM = r'''(?P<proc_pname>\w+)=(?P<proc_pval>".*?"|'.*?'|\w+)'''
     65    PROCESSOR_PARAM = r'''(?P<proc_pname>[-\w]+)''' \
     66                      r'''=(?P<proc_pval>".*?"|'.*?'|[-\w]+)'''
    6667
    6768    def _set_anchor(name, sep):
    6869        return r'=#(?P<anchorname>%s)(?:%s(?P<anchorlabel>[^\]]*))?' % \
    class WikiParser(Component):  
    225226        return wikitext
    226227
    227228
     229_processor_pname_re = re.compile(r'[-\w]+$')
     230
     231
    228232def parse_processor_args(processor_args):
    229233    """Parse a string containing parameter assignments,
    230234    and return the corresponding dictionary.
    def parse_processor_args(processor_args):  
    244248              for v in args[2::3]]
    245249    for flags in args[::3]:
    246250        for flag in flags.strip().split():
    247             if re.match(r'-?\w+$', flag):
     251            if _processor_pname_re.match(flag):
    248252                if flag[0] == '-':
    249253                    if len(flag) > 1:
    250254                        keys.append(str(flag[1:]))

We could add unit tests for parse_processor_args(). I'll post revised patch with unit tests.

comment:4 by Jun Omae, 9 years ago

Release Notes: modified (diff)

Proposed changes in [9159ea2d6/jomae.git].

Note: See TracTickets for help on using tickets.