tiddlyhost / tiddlyhost-com

Rails application for creating and hosting TiddlyWiki sites, plus resources for deploying it to https://tiddlyhost.com/
Other
188 stars 18 forks source link

Fields beginning with numbers get deleted #304

Open dfjerstad opened 1 year ago

dfjerstad commented 1 year ago

I'm having an issue where any fields starting with numbers are deleted upon saving or uploading to Tiddlyhost, using an uploaded Tiddlywiki version 5.1.17.

Expected behavior: Fields starting with numbers work like any other.

Observed behavior: Any field starting with a number will be deleted or not saved upon saving. Everything else is present upon reloading except any fields beginning with a number. A freshly uploaded Tiddlywiki file (v5.1.17) that contains fields starting with a number will not have those fields present upon viewing the uploaded wiki, with everything else intact.

simonbaird commented 1 year ago

I missed this somehow - apologies for the late response. I'll take a look at this and see if I can reproduce it.

simonbaird commented 1 year ago

I can't reproduce this in the latest TiddlyWiki, so perhaps it's a TiddlyWiki bug rather than a Tiddlyhost bug.

I'm trying it out at https://simon.tiddlyhost.com/#Fields%20with%20numbers%20test with TiddlyWiki 5.2.5.

simonbaird commented 1 year ago

I was able to reproduce this problem in an older TiddlyWiki version, (a 5.1.24-prerelease).

Actually I suspect it is related to how Tiddlyhost parses the div based storage used in pre-5.2.0 TiddlyWikis. If that's true it may be possible to provide a fix on Tiddlyhost. I'll take a look at this later.

My guess is that switch to json based storage in TiddlyWiki 5.2.0, caused this problem to go away. Are you able to upgrade your TiddlyWiki file as a workaround?

dfjerstad commented 1 year ago

Hey, thanks for responding, I kind of forgot about this as well.

I can look into updating my wiki. If it's not an issue with newer wikis then it's not a totally pressing issue for me. I'll close this as completed and let you decide whether it's an issue you'd like to address further.

dfjerstad commented 7 months ago

Hi, I have done some work trying to upgrade my wiki without success. I am wondering if you would please attempt to fix this bug?

simonbaird commented 7 months ago

Do you want some help to upgrade your TiddlyWiki?

simonbaird commented 7 months ago

https://github.com/simonbaird/tiddlyhost/wiki/Upgrading-your-site-to-the-latest-version-of-TiddlyWiki is step by step guide on how to upgrade.

dfjerstad commented 7 months ago

Thank you. The wiki is fairly customized with most of the work on it being done some time ago, so I have not been able to upgrade it cleanly. Are you willing to try to fix the bug? I don't want to take too much of your time, but I figure there might be a chance it's just a simple fix.

simonbaird commented 7 months ago

Understood. Okay, let me see if I can find a solution.

simonbaird commented 6 months ago

Experiments with the parser used by Tiddlyhost:

irb(main):038> puts Nokogiri::HTML('<div aa="value1" bb="value2" title="Asdf">').elements
<html><body><div aa="value1" bb="value2" title="Asdf"></div></body></html>

irb(main):039> puts Nokogiri::HTML('<div 1a="value1" bb="value2" title="Asdf">').elements
<html><body><div bb="value2" title="Asdf"></div></body></html>

Notice the attribute "1a" is skipped in the second example.

Experimenting with a real TiddyWiki saved in Tiddlyhost:

irb(main):044> Site.find_by_name('aaa').file_download.lines.grep /1aaa/
<div 1aaa="123" aaa="123" created="20240503172140910" modified="20240503174518514" title="Asdfasdf">

From that I can tell that the save does preserve the attribute, but when Tiddlyhost reads/parses the site (using Nokogiri) it disappears.

simonbaird commented 6 months ago

Switching from Nokogiri to Oga might be an option since it seems to be more lenient about attribute names.

>> puts Oga.parse_html('<div 1a="value1" bb="value2">').to_s
<div 1a="value1" bb="value2"></div>