Commit 5de16143 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Change order of operations for anchor generation

parent 90b22222
......@@ -4,13 +4,13 @@ module Gitlab
module Utils
module Markdown
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
PRODUCT_SUFFIX = /\((CORE|STARTER|PREMIUM|ULTIMATE)(\s+ONLY)?\)/.freeze
PRODUCT_SUFFIX = /\s*\((core|starter|premium|ultimate)(\s+only)?\)/.freeze
def string_to_anchor(string)
string
.gsub(PRODUCT_SUFFIX, '')
.strip
.downcase
.gsub(PRODUCT_SUFFIX, '')
.gsub(PUNCTUATION_REGEXP, '') # remove punctuation
.tr(' ', '-') # replace spaces with dash
.squeeze('-') # replace multiple dashes with one
......
......@@ -58,6 +58,14 @@ RSpec.describe Gitlab::Utils::Markdown do
it 'ignores a product suffix' do
is_expected.to eq 'my-header'
end
context 'with only modifier' do
let(:string) { 'My Header (STARTER ONLY)' }
it 'ignores a product suffix' do
is_expected.to eq 'my-header'
end
end
end
context 'when string is empty' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment