Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#14978 closed enhancement (worksforme)

Dojo parser: parsing comma-separated elements into an array should support a way to escape commas inside elements

Reported by: Adrian Vasiliu Owned by: bill
Priority: undecided Milestone: tbd
Component: Parser Version: 1.7.2
Keywords: Cc: cjolif
Blocked By: Blocking:

Description (last modified by cjolif)

Various widgets have properties of type Array that can be specified in mark-up using strings. For example, one can specify

<div data-dojo-type="dojox.mobile.SpinWheelSlot?"

labels="'a','b'" ...>

or <div data-dojo-type="dojox.mobile.SpinWheelSlot?"

labels="a,b" ...>

The Dojo parser transforms these comma-separated strings into an array of 2 elements (this holds for both dojo/parser and dojox/mobile/parser).

So far so good, but it seems there's currently no easy way to include a comma in an element. Say, if we need an array of 2 elements, "a,A" and "b,B", specifying

<div data-dojo-type="dojox.mobile.SpinWheelSlot?"

labels="'a,A','b,B'" ...>

the parsed array contains 4, not 2 elements.

The following attempts to escape the comma character do not work either:

<div data-dojo-type="dojox.mobile.SpinWheelSlot?"

labels="'a\,A','b\,B'" ...>

<div data-dojo-type="dojox.mobile.SpinWheelSlot?"

labels="'a&#44;A','b&#44;B'" ...>

How to reproduce:

  1. Unzip the attached testParser.zip, say into the parent folder of dojo and dijit (otherwise, adapt the paths in test.html). This contains test.html which includes in mark-up three occurrences of a dijit widget defined in TestWidget?.js, using different ways to define an array of 2 elements each containing a comma.
  2. Run test/test.html

=> The console shows the elements of the parsed arrays. In all cases, the array has 4, not 2 elements.

Attachments (1)

test.zip (1.1 KB) - added by Adrian Vasiliu 8 years ago.
Sample for reproducing.

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by Adrian Vasiliu

Attachment: test.zip added

Sample for reproducing.

comment:1 Changed 8 years ago by cjolif

Cc: cjolif added
Component: GeneralParser
Owner: set to bill

comment:2 Changed 8 years ago by cjolif

Description: modified (diff)

comment:3 Changed 8 years ago by bill

Resolution: worksforme
Status: newclosed

This already works via the data-dojo-props syntax:

data-dojo-props='labels: ["A, a", "B, b"]'

Let us know if there's something else you need.

I don't see a reason to have this functionality on direct widget attributes (ie, attributes like label in your example above) since our trend is to only use direct attributes where there are corresponding native DOMNode attributes (as defined in the HTML spec).

comment:4 Changed 8 years ago by Adrian Vasiliu

Yes, using data-dojo-props it works fine indeed. Thanks for the hint.

Note: See TracTickets for help on using tickets.