Unverified Commit 12deda14 authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff
Browse files

Change regexp for hashtags

Fixes #5765, fixes #5815, supersedes #6099.

closes #7350
parent 7d2e6c63
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
* Remove whitespace from author link [#7330](https://github.com/diaspora/diaspora/pull/7330)
* Fix autosize in modals [#7339](https://github.com/diaspora/diaspora/pull/7339)
* Only display invite link on contacts page if invitations are enabled [#7342](https://github.com/diaspora/diaspora/pull/7342)
* Fix regex for hashtags for some languages [#7350](https://github.com/diaspora/diaspora/pull/7350)

## Features
* Add support for [Liberapay](https://liberapay.com) donations [#7290](https://github.com/diaspora/diaspora/pull/7290)
+8 −1
Original line number Diff line number Diff line
@@ -37,7 +37,14 @@
    var hashtagPlugin = window.markdownitHashtag;
    md.use(hashtagPlugin, {
      // compare tag_text_regexp in app/models/acts_as_taggable_on-tag.rb
      hashtagRegExp: "[" + PosixBracketExpressions.alnum + "_\\-]+|<3",
      hashtagRegExp: "[" + PosixBracketExpressions.word +
                           "\\u055b" + // Armenian emphasis mark
                           "\\u055c" + // Armenian exclamation mark
                           "\\u055e" + // Armenian question mark
                           "\\u058a" + // Armenian hyphen
                           "_" +
                           "\\-" +
                     "]+|<3",
      // compare tag_strings in lib/diaspora/taggabe.rb
      preceding: "^|\\s"
    });
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ module ActsAsTaggableOn
    self.include_root_in_json = false

    def self.tag_text_regexp
      @@tag_text_regexp ||= "[[:alnum:]]_-"
      @tag_text_regexp ||= "[[:word:]]\u055b\u055c\u055e\u058a_-"
    end

    def self.autocomplete(name)
+1360 −443

File changed.

Preview size limit exceeded, changes collapsed.

+31 −6
Original line number Diff line number Diff line
@@ -9,21 +9,46 @@ describe("app.helpers.textFormatter", function(){
  // https://github.com/svbergerem/markdown-it-hashtag/tree/master/test
  context("hashtags", function() {
    beforeEach(function() {
      this.tags = [
      this.goodTags = [
        "tag",
        "diaspora",
        "PARTIES",
        "<3"
        "<3",
        "diaspora-dev",
        "diaspora_dev",
        // issue #5765
        "മലയാണ്മ",
        // issue #5815
        "ինչո՞ւ",
        "այո՜ո",
        "սեւ֊սպիտակ",
        "գժանո՛ց"
      ];

      this.badTags = [
        "tag.tag",
        "hash:tag",
        "hash*tag"
      ];
    });

    it("renders tags as links", function() {
      var formattedText = this.formatter('#'+this.tags.join(" #"));
      _.each(this.tags, function(tag) {
        var link ='<a href="/tags/'+tag.toLowerCase()+'" class="tag">#'+tag.replace("<","&lt;")+'</a>';
    it("renders good tags as links", function() {
      var self = this;
      this.goodTags.forEach(function(tag) {
        var formattedText = self.formatter("#newhashtag #" + tag + " test");
        var link = "<a href=\"/tags/" + tag.toLowerCase() + "\" class=\"tag\">#" + tag.replace("<", "&lt;") + "</a>";
        expect(formattedText).toContain(link);
      });
    });

    it("doesn't render bad tags as links", function() {
      var self = this;
      this.badTags.forEach(function(tag) {
        var formattedText = self.formatter("#newhashtag #" + tag + " test");
        var link = "<a href=\"/tags/" + tag.toLowerCase() + "\" class=\"tag\">#" + tag.replace("<", "&lt;") + "</a>";
        expect(formattedText).not.toContain(link);
      });
    });
  });

  // Some basic specs. For more detailed specs see
Loading