Jermolene/TiddlyWiki5

[BUG] The $action-setfield widget and the empty $field parameter

Closed this issue · 3 comments

Describe the bug
In https://tiddlywiki.com/#ActionSetFieldWidget it states

The value to be assigned to the field or index identified by the $field or $index attribute. If neither is specified then the value is assigned to the text field. If no value is specified, $field or $index will be deleted.

which means when user does NOT pass the $field, Tiddlywiki uses text field as default. But assume when you use $field with a filter to select a field of a target tiddler programatically and the filter returns empty value! In this case also $action-setfield with empty $field overwrites the text field of target tiddler.

To Reproduce
Steps to reproduce the behavior:

  1. Open https://tiddlywiki.com
  2. Create a tiddler with title: test, text: "Hello Tiddlywiki"
  3. Create another tiddler with the below wikitext and save
<$button>Create a Field
<$action-setfield $tiddler="test" 
 $field=""
 $value="fg"
/>
</$button>
  1. Click on "Create Filed" button from step 3 above
  2. Tiddlywiki replaces the text field of test tiddler with the value given in $value parameter

Expected behavior
When the $field is passed but is empty , $action-setfield can ignore the operation. I am not sure if this break backward compatibility or not.

Desktop

  • OS: Windows 10
  • Chrome 81
  • Tiddlywiki 5.1.23 pre

But assume when you use $field with a filter to select a field of a target tiddler programatically and the filter returns empty value! In this case also $action-setfield with empty $field overwrites the text field of target tiddler.

it's relatively easy to make sure, that a filter always returns a value. see the else operator

Thanks Mario. Isn't there any difference between sending a argument with an empty value like <$action-setfield $tiddler="test" $field="" and not sending an argument (attribute) like <$action-setfield $tiddler="test" .
Well I can use $list and conditional expression to handle this issue but it is a little complicated.

TiddlyWiki uses sensible defaults in most cases. That makes it possible to fail silent. Otherwise we would have ROSDs (Red screen of "death") all the time, something isn't defined. Javascript can be really nasty, if variables are not defined. So almost everything uses defaults if params are missing.