PrimalHQ / primal-web-app

Primal's web app for Nostr, as experienced on primal.net.
https://primal.net
MIT License
200 stars 39 forks source link

Tags incorrect for hashtags #17

Closed Dolu89 closed 1 year ago

Dolu89 commented 1 year ago

Describe the bug

I created a note for a test starting with #test on primal.net. Tags result was "tags": [ ["t", "est"] ]

Steps to reproduce

Create a note containing a hashtag (maybe only starting with hashtag? Not tried)

Expected behavior

"tags": [ ["t", "test"] ]

Environment

Additional context

ID of the created note using primal.net here nevent1qqsfx3y678xl9nfnxfj87wxtthdacqmaef4gmcmd7cwg5vz3ma2r2scfcktqv https://www.nostr.guru/e/93449af1cdf2cd3332647f38cb5ddbdc037dca6a8de36df61c8a3051df543543

unwired01 commented 1 year ago

Yes, I was able to duplicate the circumstance.

image

"tags": [ [ "t", "est" ] ],

I will try to solve it

unwired01 commented 1 year ago

The problem

Slicing text from hashtag works only for words with blank space before the hashtag _#test

Example note: #test another #onlyzap for a project #zapathon #eurothon The only word without a blank space before it is the word "test."

For the code:

// Parse hashtags to add to tags
  while((match = regexHashtag.exec(value)) != null) {
    hashtags.push(match[0]);`
  }

This is the output: ["#test", " #onlyzap", " #zapathon", " #eurothon"] You can see the empty blanks

And when slicing the hashtag:

tags = hashtags.map(h => ['t', h.slice(2)]); This is the output: [["t", "est"], ["t", "onlyzap"], ["t", "zapathon"], ["t", "eurothon"]]

Solution

Trim words before slicing


  // Parse hashtags to add to tags
  while((match = regexHashtag.exec(value)) != null) {
    hashtags.push(match[0].trim());
  }

And then change the slice to first letter after hashtag

tags = hashtags.map(h => ['t', h.slice(1)]);

I made the change but I cannot push the commit

unwired01 commented 1 year ago

I forgot to add the output for my code

The trim remove the blank space ["#test", "#onlyzap", "#zapathon", "#eurothon"]

The slice(1) - slice the text from the hashtag [["t", "test"], ["t", "onlyzap"], ["t", "zapathon"], ["t", "eurothon"]]

moysa commented 1 year ago

Hi. Thank you for reporting this. The fix similar to what @unwired01 proposed will be in the next release

unwired01 commented 1 year ago

@moysa I see that I made a mistake and erased my pr code. I can restore it if you need.

moysa commented 1 year ago

Hi, no need. The fix is currently on the dev branch and will be merged into main on the next release (https://github.com/PrimalHQ/primal-web-app/commit/53edb4da29bc7396e7972cd89ad1d60cd99c48e7). It isn't exactly your proposed changes line-by-line, but essentially the same.

moysa commented 1 year ago

Fix for this has now been released in v0.74.8. Closing