diff --git a/README.md b/README.md index 1ee35b1..f0e2e45 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This GitHub Action will expose the slug/short values of [some GitHub environment `SLUG` on a variable will - put the variable content in lower case -- replace any character by `-` except `0-9`, `a-z`, and `.` +- replace any character by `-` except `0-9`, `a-z`, `.`, and `_` - remove leading and trailing `-` character - limit the string size to 63 characters diff --git a/__tests__/slugref.test.ts b/__tests__/slugref.test.ts index 728937e..f8b08bf 100644 --- a/__tests__/slugref.test.ts +++ b/__tests__/slugref.test.ts @@ -16,13 +16,13 @@ test('slug_ref:: master branch', () => { }) test('slug_ref: a feature branch', () => { - test_slugref('refs/heads/feat/new_feature', 'feat-new-feature') - test_slugref_cs('refs/heads/feat/new_feature', 'feat-new-feature') + test_slugref('refs/heads/feat/new_feature', 'feat-new_feature') + test_slugref_cs('refs/heads/feat/new_feature', 'feat-new_feature') }) test('slug_ref: a fix branch', () => { - test_slugref('refs/heads/fix/issue_number', 'fix-issue-number') - test_slugref_cs('refs/heads/fix/issue_number', 'fix-issue-number') + test_slugref('refs/heads/fix/issue_number', 'fix-issue_number') + test_slugref_cs('refs/heads/fix/issue_number', 'fix-issue_number') }) test('slug_ref: a simple tag', () => { @@ -36,8 +36,8 @@ test('slug_ref: a complex tag', () => { }) test('slug_ref: a reference with upper case letters', () => { - test_slugref('refs/heads/New_Awesome_Product', 'new-awesome-product') - test_slugref_cs('refs/heads/New_Awesome_Product', 'New-Awesome-Product') + test_slugref('refs/heads/New_Awesome_Product', 'new_awesome_product') + test_slugref_cs('refs/heads/New_Awesome_Product', 'New_Awesome_Product') }) test('slug_ref: test trailing', () => { diff --git a/src/slug.ts b/src/slug.ts index fee84c8..7919bc9 100644 --- a/src/slug.ts +++ b/src/slug.ts @@ -2,7 +2,7 @@ const MAX_SLUG_STRING_SIZE = 63 /** * slug_cs will take envVar and then : - * - replace any character by `-` except `0-9`, `a-z`, and `.` + * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - remove leading and trailing `-` character * - limit the string size to 63 characters * @param envVar to be slugged @@ -17,7 +17,7 @@ export function slug_cs(envVar: string): string { /** * slug will take envVar and then : * - put the variable content in lower case - * - replace any character by `-` except `0-9`, `a-z`, and `.` + * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - remove leading and trailing `-` character * - limit the string size to 63 characters * @param envVar to be slugged @@ -29,7 +29,7 @@ export function slug(envVar: string): string { /** * slugref_cs will take envVar and then : * - remove refs/(heads|tags|pull)/ - * - replace any character by `-` except `0-9`, `a-z`, and `.` + * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - remove leading and trailing `-` character * - limit the string size to 63 characters * @param envVar to be slugged @@ -42,7 +42,7 @@ export function slugref_cs(envVar: string): string { * slugref will take envVar and then : * - remove refs/(heads|tags|pull)/ * - put the variable content in lower case - * - replace any character by `-` except `0-9`, `a-z`, and `.` + * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - remove leading and trailing `-` character * - limit the string size to 63 characters * @param envVar to be slugged @@ -59,7 +59,7 @@ export function slugref(envVar: string): string { * @param envVar to be slugged */ export function slugurl_cs(envVar: string): string { - return slug_cs(replaceAnyDotToHyphen(envVar)) + return slug_cs(replaceAnyNonUrlCharactersWithHyphen(envVar)) } /** @@ -71,7 +71,7 @@ export function slugurl_cs(envVar: string): string { * @param envVar to be slugged */ export function slugurl(envVar: string): string { - return slug(replaceAnyDotToHyphen(envVar)) + return slug(replaceAnyNonUrlCharactersWithHyphen(envVar)) } /** @@ -104,11 +104,11 @@ function trailHyphen(envVar: string): string { } function replaceAnyNonAlphanumericCharacter(envVar: string): string { - return envVar.replace(RegExp('[^a-zA-Z0-9.]', 'g'), '-') + return envVar.replace(RegExp('[^a-zA-Z0-9._]', 'g'), '-') } -function replaceAnyDotToHyphen(envVar: string): string { - return envVar.replace(RegExp('[.]', 'g'), '-') +function replaceAnyNonUrlCharactersWithHyphen(envVar: string): string { + return envVar.replace(RegExp('[._]', 'g'), '-') } function removeRef(envVar: string): string {