Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Internal JavaScript Error on giving invalid "tag" attribute values for certain widgets #8166

Open
bluepenguindeveloper opened this issue Apr 25, 2024 · 8 comments · May be fixed by #8176

Comments

@bluepenguindeveloper
Copy link

bluepenguindeveloper commented Apr 25, 2024

Describe the bug

The code <$droppable <$macrocall $name="tag" tag="$:/tags/Global"/> results in the Internal JavaScript Error Uncaught InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('$:/tags/Global') is not a valid name.

Edit: Certain widgets that support overriding the default HTML tag for the widget cause uncaught JS errors when given an invalid value for the "tag" attribute. For example, <$edit-text tag="$"/> or <$droppable tag="$"/>.

Expected behavior

JS error is caught and a syntax error should be displayed

To Reproduce

  1. Go to tiddlywiki.com or open an Empty wiki
  2. Open new tiddler
  3. Open side-by-side preview pane
  4. Paste <$droppable <$macrocall $name="tag" tag="$:/tags/Global"/> into the editor
    Edit: simply paste <$droppable tag="$"/>
  5. Internal JavaScript Error message pops up

Screenshots

image

TiddlyWiki Configuration

  • Version v5.3.3
  • Saving mechanism TiddlyDesktop, or none

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chromium-based (at least Brave and TiddlyDesktop)

Additional context

Edit: The below behavior was part of how this was discovered and the cause determined, but now that the example of <$edit-text tag="$"/> is known, the below examples are no longer needed to understand the issue.

  • The error also occurs if calling the macro using the <$transclude> widget ( <$droppable <$transclude $variable="tag" tag="$:/tags/Global"/>)
  • The error does not occur when using the wikitext macrocall syntax (<$droppable <<tag "$:/tags/Global">>)
  • The error does not occur if the tag name only includes alphabetic characters (e.g., in the documentation, <$droppable <$macrocall $name="tag" tag="Macros"/>); it appears the dollar sign $ in the tag name is partially the cause of the issue.

Note: The original intention was to complete the full <$droppable> widget, adding it around an existing <$macrocall> widget. But when typing <$droppable> one character at a time, you get to <$droppable and the error occurs before you can finish off with the >. (The point being that this isn't merely what you can find by experimenting with invalid syntax in attempt to break TW; it first happened to me in the natural course of trying to write valid syntax with the preview pane open.)

@bluepenguindeveloper
Copy link
Author

Just figured out that the simplest form to reproduce the issue is: <$droppable tag="$" />

The reason why the transclude widget and macro call widget, but not the macrocall wikitext syntax (<<tag "$:/tags/Global">>), causes the error is that, before typing >, the contents, including tag="$:/tags/Global" get parsed as an attribute to the <$droppable> widget.

My suspicion is that this can happen with any widget that accepts tag as an attribute (for specifying the HTML tag generated by the widget), if you include invalid characters.

@pmario
Copy link
Contributor

pmario commented Apr 25, 2024

Forget my comment at Talk. It's a different issue. Sorry. I did not look good enough

@pmario
Copy link
Contributor

pmario commented Apr 25, 2024

<$droppable <$transclude $variable="tag" tag="$:/tags/Global"/>

The droppable widget has a tag-parameter, which is used to create DIVs or SPANs .. The "tag" parameter of the transclude-widget is parsed as an input for the draggable-widget. The draggable now thinks we want to create a $:/tags/xx HTML element, which is not allowed.

I'm not sure if there is an easy solution to this one -- We probably should fall back to create a SPAN or DIV if the tag-attribute is invalid. There is no validity check at the moment, since the browser throws an exception, which you can see

@bluepenguindeveloper
Copy link
Author

Yep, it seems anything that allows you to override the HTML element through a "tag" attribute has the issue. For example, even <$edit-text tag="$"/> results in the same error.

And yes, I would think falling back would be reasonable if the specified HTML tag is invalid, or alternatively, rendering an error message similar to "Undefined widget: xxx" or "Filter error: xyz" (rather than leaving an uncaught JS error).

@bluepenguindeveloper bluepenguindeveloper changed the title [BUG] Internal JavaScript Error on incomplete DroppableWidget around tag macrocall [BUG] Internal JavaScript Error on giving invalid "tag" attribute values for certain widgets Apr 25, 2024
@bluepenguindeveloper
Copy link
Author

bluepenguindeveloper commented Apr 25, 2024

Also edited the bug to be more to the point, now that we know what the issue really is (while leaving the original in strikethrough)

@Jermolene
Copy link
Owner

Thanks @bluepenguindeveloper – this should be fairly straightforward to fix, and might make a good first PR for somebody.

@bluepenguindeveloper
Copy link
Author

Thanks @bluepenguindeveloper – this should be fairly straightforward to fix, and might make a good first PR for somebody.

This feels like an invitation, so I'm starting to read the developer docs and CLA just in case the time has come for me to contribute. But I'm curious about one thing: would I be required to add my real name to the public list of contributors, or would it be possible for me to remain pseudonymous (at least publicly)? I see a few entries with just the GitHub username but it looks like the vast majority include a real full name.

@pmario
Copy link
Contributor

pmario commented Apr 26, 2024

@bluepenguindeveloper ... There are several users signing CLA with their alias. So it should be good for you too.

@pmario pmario linked a pull request May 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants