tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

Disallow link markup in strings used as macro arguments #217

Closed tmedwards closed 2 months ago

tmedwards commented 1 year ago

What it says on the tin. Authors are confusing the actual link markup with macros' link markup style syntax.

It's currently possible to do the following:

<<link "[[fubar]]">><</link>>

<<link `either("[[fubar]]", "[[snafu]]")`>><</link>>

This causes the link markup within the string to be rendered within the link generated by the macro. E.g.,

<a><a>fubar</a></a>

This is obviously bad and can lead to hard to diagnose buggy behavior, since each link has their own event handlers.

The actual intent of authors doing this is to use the link markup style macro argument syntax. For example:

<<link [[fubar]]>><</link>>

<<link [[either("good", "okay")]]>><</link>>

Potential Fixes

  1. Somehow detect the lossage, pre-render, and throw an error.
  2. Disallow the link markup within the text of link-y macros via profiles or something like that.
  3. Have link-y (and button-y) macros detect anchor elements (<a>) within their rendered text and throw an error.

I'm currently leaning towards option 3.