-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanitize.spec.js
157 lines (129 loc) · 4.66 KB
/
sanitize.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const sanitize = require('./sanitize')
describe('sanitize', () => {
describe('output', () => {
// https://stackoverflow.com/questions/3651860/which-characters-are-illegal-within-a-branch-name
it('allow "/" char', () => {
const output = sanitize('foo/bar')
expect(output).toBe('foo/bar')
})
it('should remove dot from "/."', () => {
const output = sanitize('foo/.bar/.baz')
expect(output).toBe('foo/bar/baz')
})
it('should separate ".lock" at the end of the slash separated sequence', () => {
const output = sanitize('foo.lock.foo/bar.lock/baz.lock', '+')
expect(output).toBe('foo.lock.foo/bar+lock/baz+lock')
})
it('should separate ".."', () => {
const output = sanitize('foo..bar...baz', '+')
expect(output).toBe('foo+bar+.baz')
})
it('should separate ".." and remove dot from "/."', () => {
const output = sanitize('foo...bar', '/')
expect(output).toBe('foo/bar')
})
it('should separate ".." and remove dot from ".lock"', () => {
const output = sanitize('foo...lock', '/')
expect(output).toBe('foo/lock')
})
it('should remove "~"', () => {
const output = sanitize('foo~~/~bar', '+')
expect(output).toBe('foo/bar')
})
it('should remove "^"', () => {
const output = sanitize('foo^^/^bar', '+')
expect(output).toBe('foo/bar')
})
it('should remove ":"', () => {
const output = sanitize('foo::bar', '+')
expect(output).toBe('foobar')
})
it('should separate space', () => {
const output = sanitize('foo bar baz', '/')
expect(output).toBe('foo/bar/baz')
})
it('should use one separator to replace multiple spaces', () => {
const output = sanitize('foo bar', '/')
expect(output).toBe('foo/bar')
})
it('should replace "\"', () => {
const output = sanitize('foo\\bar', '+')
expect(output).toBe('foobar')
})
it('should remove ".." at the end of the input', () => {
const output = sanitize('foo....bar..', '/')
expect(output).toBe('foo/bar')
})
it('should remove "@{"', () => {
const output = sanitize('foo@{@{bar')
expect(output).toBe('foobar')
})
it('should remove "?"', () => {
const output = sanitize('foo??bar')
expect(output).toBe('foobar')
})
it('should remove "*"', () => {
const output = sanitize('foo**bar**')
expect(output).toBe('foobar')
})
it('should remove "["', () => {
const output = sanitize('foo[[bar[')
expect(output).toBe('foobar')
})
it('should collapse multiple "/"', () => {
const output = sanitize('foo// bar / baz', '/')
expect(output).toBe('foo/bar/baz')
})
it('should remove separator at the beginning of the section', () => {
const output = sanitize('foo/ bar', '+')
expect(output).toBe('foo/bar')
})
})
describe('separator', () => {
it('should throw on space separator', () => {
expect(() => {
sanitize('foo', 'bar ')
}).toThrow()
})
it('should throw on ".." separator', () => {
expect(() => {
sanitize('foo', 'bar..')
}).toThrow()
})
it('should throw on "~" separator', () => {
expect(() => {
sanitize('foo', 'bar~')
}).toThrow()
})
it('should throw on "^" separator', () => {
expect(() => {
sanitize('foo', 'bar^')
}).toThrow()
})
it('should throw on ":" separator', () => {
expect(() => {
sanitize('foo', 'bar:')
}).toThrow()
})
it('should throw on "?" separator', () => {
expect(() => {
sanitize('foo', 'bar?')
}).toThrow()
})
it('should throw on "*" separator', () => {
expect(() => {
sanitize('foo', 'bar*')
}).toThrow()
})
it('should throw on "[" separator', () => {
expect(() => {
sanitize('foo', 'bar[')
}).toThrow()
})
it('should throw on "@" separator', () => {
expect(() => {
sanitize('foo', 'bar@')
}).toThrow()
})
})
})