am_attributes2set C command (also includes am_unquotehtml, am_quotehtml commands)


AOLserver ADP Fancy Parser parses tag attributes and creates an ns_set out of them (and does so very quickly).  We thought it would be very convenient to have this attribute string parsing exposed as a Tcl command.  So, we made some modifications to the ParseAtts function from AOLserver 4.0's adpparse.c and made it into a command - am_attributes2set.

Since attributes values in XML tags must be html-quoted, to be able to parse an XML tag with am_attributes2set, we needed it to optionally html-unquote values, so we added an am_unquotehtml command to this module.  While we were at it, we also threw in an am_quotehtml command which is essentially a better/more flexible version of ns_quotehtml.

These two commands we previously had written in Tcl but since html-quoting formdata to prevent cross-site scripting vulnerabilities is a good practice, having faster versions of these commands is helpful.

Installation is the same as for any other AOLserver module: place the compiled amattributes2set.dll/ into the bin directory and in the config file under ns_section "ns/server/$server/modules" add
ns_param amattributes2set ${bindir}/amattributes2set${ext}

Next restart your AOLserver, check your Server Log for errors.

am_attributes2set ?-minimize? ?-unquote? string

am_quotehtml string ?single? ?double?   OR   am_quotehtml string ?single | double?

am_unquotehtml string


am_attributes2set takes a string like {a=b c='d' e="f" selected} and turns it into an ns_set. (This is the logical inverse of our tcl am_set2attributes proc).  By default, we handle boolean attributes the same way AOLserver 4 does when creating an ns_set of attributes to pass to the proc registered for a fancy adp tag - that is, we set the key to the value.

If a switch that starts with "-minimize" is passed, we instead use a zero-length key.
(This is to allow round-tripping such an ns_set back to attributes using our tcl am_set2attributes proc with bypass in onEmptyKey parameter.)

If a switch that starts with "-unquote" is passed we html-unquote the values (not keys). Note that you can use a more precisely-worded switch in your tcl code
(i.e. am_attributes2set -unquotehtmlValuesOnly) as long as it starts with -unquote.

am_quotehtml is analogous to ns_quotehtml except that it quotes double-quotes as " and single quotes as ' (ns_quotehtml in AOLserver 2.x does not quote single or double-quotes at all and in 3.x+ uses " for double-quotes)

Optional arguments that contain the strings "single" and/or "double" can be passed.

  • If the 2nd or 3rd argument contains the string "double", double-quotes will NOT be converted
  • If the 2nd or 3rd argument contains the string "single", single-quotes will NOT be converted

To clarify, the following are all valid ways of calling this command:

am_quotehtml string single double
am_quotehtml string double single
am_quotehtml string "single double"
am_quotehtml string -nosinglequotes
am_quotehtml string "-nodoublequotes nosinglequotes"
am_quotehtml string -nodoubleorsinglequotes

am_unquotehtml does the reverse of ns_quotehtml and am_quotehtml (i.e. it handles both " and " escapes for double-quotes)

URL Aliases | amattributes2set | ampools | ADP Master Pages

© Copyright 1996-2014 by and Solitex Networks. Legal Notices.
Creative Commons License Articles on this site are licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.