I tried the following in a drupal with a bunch of other modules and also in a clean install of drupal 7.9.

If a user writes a message and the first letter is "#" followed with a word, statuses don't turn that into a term and just shows it as plain text.

I'm not sure if this is a bug, I just report it for your knowledge.

Keep up the good work!

trevonio

Comments

carlos_lopez_trevonio’s picture

Well, actually statuses inserts the new term but still shows the word as plain text.

icecreamyou’s picture

Status: Active » Postponed (maintainer needs more info)

I can't reproduce this. Maybe it has something to do with an input filter you have running over the statuses?

carlos_lopez_trevonio’s picture

It happens when "plain text" is configured as input filter in statuses settings but not when "none" is configured as input filter.

Is that its normal behaviour?

icecreamyou’s picture

Title: If a status message starts with an # won't turn into a term » If a status message starts with a # the word won't turn into a term with the Convert line breaks into HTML input filter enabled
Priority: Normal » Minor
Status: Postponed (maintainer needs more info) » Active

Ah, got it. The problem is that the Convert line breaks into HTML (i.e. <br> and <p>) input filter (which is enabled in the default Plain Text input format) wraps status updates in <p> tags. When the Tags submodule gets the status, it looks like <p>#term status</p> and the sequence >#word apparently doesn't register as being a separate term. That should be fixable, but the easiest solution short term is to just disable that input filter and use the "Convert line breaks" advanced setting for Statuses instead.

carlos_lopez_trevonio’s picture

Will do that, thanks!

carlos_lopez_trevonio’s picture

Status: Active » Postponed

With your permission changing the status to postponed because the reasons are clear now.

mathankumarc’s picture

Status: Postponed » Active
Issue tags: +Needs backport to D6

I could see the same issue in FBSS 3.x branch also.

tagging.

icecreamyou’s picture

The regex that parses #hashtags/@mentions is super scary:

%((?:\A|(?<=\s))(?:#|@)(\w|(\p{L}\p{M}?))+\b)|(\[(#|@)[^\]]+\])%u

...and its non-unicode variant:

%((?:\A|(?<=\s))(?:#|@)\w+\b)|(\[(#|@)[^\]]+\])%u

I have no idea how some of that works. I got help writing it from someone in #regex on Freenode over 2 years ago and I have not touched it since. There are a ton of cases it needs to get right and this is the first time I've come across a case it handles incorrectly.

icecreamyou’s picture

Version: 7.x-1.0-unstable3 » 7.x-1.x-dev
Status: Active » Fixed

Re-reading this, it's not so bad. Here's an explanation:

%
  (   // This section matches single-word #hashtags or @mentions not surrounded by [square brackets]
    (   // This section matches the position for the start of a hashtag (the beginning of the status or after whitespace).
      ?:\A |   // Match the position of the start of the string (\A) without creating a backreference (?:), OR:
      (?<=\s)   // Positive-lookbehind (?<=) for whitespace (\s)
    )
    (?:#|@)   // Match a # or @ sign at the beginning of a hashtag without creating a backreference
    (\w|(\p{L}\p{M}?))+\b   // Match one or more word characters (\w) or multi-byte unicode characters (\p{L}\p{M}?) followed by a word break (\b)
  ) |
  (   // This section matches multi-word tags surrounded by [square brackets]
    \[(#|@)[^\]]+\]   // Opening square bracket (\[) followed by # or @ followed by one or more characters that are not closing square brackets ([^\]]) followed by closing square bracket (\])
  )
%u   // Treat strings as unicode

Likely the source of the problem in this issue is that the (?:\A|(?<=\s)) section treats the HTML tag's closing angle bracket as text rather than markup so it assumes that the hashtag is part of a larger word. There is not a generic way to resolve this using regex because explicitly matching against the closing angle bracket would permit tags in cases like text >#tag text which we don't want, and generically matching full HTML tags is impossible.

I'm prepared to chalk it up under "known problems" that tags won't work without square brackets immediately following HTML markup, which I think is acceptable given that we have an explicit workaround already for the single case where this is likely to occur. I documented this case.

Automatically closed -- issue fixed for 2 weeks with no activity.