@@ -15,14 +15,24 @@ import (
15
15
)
16
16
17
17
var (
18
- transformer transform.Transformer
18
+ transformer = transform .Chain (norm .NFD , runes .Remove (runes .In (unicode .Mn )), norm .NFC )
19
+ transliterations = map [string ]string {
20
+ "Ð" : "D" ,
21
+ "Ł" : "l" ,
22
+ "Ø" : "oe" ,
23
+ "Þ" : "Th" ,
24
+ "ß" : "ss" ,
25
+ "æ" : "ae" ,
26
+ "ð" : "d" ,
27
+ "ł" : "l" ,
28
+ "ø" : "oe" ,
29
+ "þ" : "th" ,
30
+ "œ" : "oe" ,
31
+ }
32
+ quotesChar = regexp .MustCompile (`["'` + "`" + `](?m)` )
19
33
specialChars = regexp .MustCompile (`[^a-z0-9.\-_/](?m)` )
20
34
)
21
35
22
- func init () {
23
- transformer = transform .Chain (norm .NFD , runes .Remove (runes .In (unicode .Mn )), norm .NFC )
24
- }
25
-
26
36
// GetPathname computes pathname for given params
27
37
func GetPathname (folder , name string , share * Share ) string {
28
38
parts := make ([]string , 0 )
@@ -59,20 +69,28 @@ func GetURI(folder, name string, share *Share) string {
59
69
60
70
// SanitizeName return sanitized name (remove diacritics)
61
71
func SanitizeName (name string , removeSlash bool ) (string , error ) {
62
- withoutDiacritics , _ , err := transform .String (transformer , strings .ToLower (name ))
72
+ withoutLigatures := strings .ToLower (name )
73
+ for key , value := range transliterations {
74
+ if strings .Contains (withoutLigatures , key ) {
75
+ withoutLigatures = strings .ReplaceAll (withoutLigatures , key , value )
76
+ }
77
+ }
78
+
79
+ withoutDiacritics , _ , err := transform .String (transformer , withoutLigatures )
63
80
if err != nil {
64
81
return "" , err
65
82
}
66
83
67
84
withoutSpaces := strings .Replace (withoutDiacritics , " " , "_" , - 1 )
68
- withoutSpecials := specialChars .ReplaceAllString (withoutSpaces , "" )
85
+ withoutQuotes := quotesChar .ReplaceAllString (withoutSpaces , "_" )
86
+ withoutSpecials := specialChars .ReplaceAllString (withoutQuotes , "" )
69
87
70
88
sanitized := withoutSpecials
71
89
if removeSlash {
72
90
sanitized = strings .Replace (sanitized , "/" , "_" , - 1 )
73
91
}
74
92
75
- return sanitized , nil
93
+ return strings . Replace ( sanitized , "__" , "_" , - 1 ) , nil
76
94
}
77
95
78
96
// SafeWrite writes content to writer with error handling
0 commit comments