kpumuk / meta-tags

Search Engine Optimization (SEO) for Ruby on Rails applications.
MIT License
2.73k stars 275 forks source link

Title truncation counts escaped entity length #179

Closed jessecampos closed 5 years ago

jessecampos commented 5 years ago

If a character in a title is escaped, this counts toward the truncation length limit. For example, " would be counted as 6 characters for " instead of one.

I've added a test case showing this: jessecampos@f292824

result

1) MetaTags::TextNormalizer.normalize_title when site_title is specified should truncate title when limit is reached on unescaped value
     Failure/Error: expect(subject.normalize_title(site_title, title, '-')).to eq("#{site_title}-#{'"' * (MetaTags.config.title_limit - 21)}")

       expected: "aaaaaaaaaaaaaaaaaaaa-"""""""""""""&...ot;"""""""""""""""""
            got: "aaaaaaaaaaaaaaaaaaaa-""""""""&"

       (compared using ==)

I can work on a fix if this is something you're willing to change.

kpumuk commented 5 years ago

@jessecampos Thank you for the report, awesome catch!