Switch slugify regex to support more Unicode character groups (#8167)

Merge pull request 8167
This commit is contained in:
matt swanson 2020-05-14 02:20:20 -04:00 committed by GitHub
parent 11dd893416
commit f8286b62a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -13,8 +13,8 @@ module Jekyll
# Constants for use in #slugify
SLUGIFY_MODES = %w(raw default pretty ascii latin).freeze
SLUGIFY_RAW_REGEXP = Regexp.new('\\s+').freeze
SLUGIFY_DEFAULT_REGEXP = Regexp.new("[^[:alnum:]]+").freeze
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
SLUGIFY_DEFAULT_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}]+").freeze
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}._~!$&'()+,;=@]+").freeze
SLUGIFY_ASCII_REGEXP = Regexp.new("[^[A-Za-z0-9]]+").freeze
# Takes a slug and turns it into a simple title.

View File

@ -176,6 +176,11 @@ class TestUtils < JekyllUnitTest
assert_equal "5時-6時-三-一四", Utils.slugify("5時〜6時 三・一四")
end
should "not replace Unicode 'Mark', 'Letter', or 'Number: Decimal Digit' category characters" do
assert_equal "மல்லிப்பூ-வகைகள்", Utils.slugify("மல்லிப்பூ வகைகள்")
assert_equal "மல்லிப்பூ-வகைகள்", Utils.slugify("மல்லிப்பூ வகைகள்", :mode => "pretty")
end
should "not modify the original string" do
title = "Quick-start guide"
Utils.slugify(title)