Skip to content

Commit 3b45ccb

Browse files
alinelariguetjhosefmarks
authored andcommitted
fix(url): corrige validação de links que contenham caracteres maiúsculos
Validação considera caracteres tanto maiúsculos quanto minúsculos. Fixes DTHFUI-2142
1 parent fd04afc commit 3b45ccb

File tree

2 files changed

+118
-3
lines changed

2 files changed

+118
-3
lines changed

projects/ui/src/lib/components/po-field/po-url/po-url.component.spec.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,91 @@ describe('PoUrlComponent:', () => {
8484
expect(component.inputEl.nativeElement.removeEventListener).not.toHaveBeenCalled();
8585
});
8686

87+
it('url: should be valid with the values', fakeAsync(() => {
88+
const urls = [
89+
`http://foo.com/blah_blah/`,
90+
`http://foo.com/blah_blah?ah5SF0-Hgr`,
91+
`http://foo.com/blah_blah?ah5SF0Hgr`,
92+
`http://foo.com/blah_blah/`,
93+
`http://www.example.com/wpstyle/?p=364`,
94+
`https://www.example.com/foo/?bar=baz&inga=42&quux`,
95+
`http://142.42.1.1/`,
96+
`http://142.42.1.1:8080/`,
97+
`http://j.mp`,
98+
`http://foo.bar/?q=Test%20URL-encoded%20stuff`,
99+
`http://1337.net`,
100+
`http://a.b-c.de`,
101+
`http://223.255.255.254`,
102+
`http://0.0.0.0`,
103+
`http://a.b--c.de/`,
104+
`foo.com`
105+
];
106+
107+
const regExpUrl = new RegExp(component.pattern);
108+
109+
urls.forEach(url => {
110+
expect(regExpUrl.test(url)).toBeTruthy(`URL ${url} is not a valid URL.`);
111+
});
112+
}));
113+
114+
it('url: shouldn`t be valid with the values', fakeAsync(() => {
115+
const urls = [
116+
`http://`,
117+
`http://.`,
118+
`http://.. `,
119+
`http://../`,
120+
`http://?`,
121+
`http://?? `,
122+
`http://??/`,
123+
`http://#`,
124+
`http://## `,
125+
`http://##/`,
126+
`http://foo.bar?q=Spaces should be encoded `,
127+
`//`,
128+
`//a `,
129+
`///a`,
130+
`/// `,
131+
`http:///a `,
132+
`rdar://1234 `,
133+
`h://test`,
134+
`http:// shouldfail.com `,
135+
`:// should fail `,
136+
`http://foo.bar/foo(bar)baz quux `,
137+
`ftps://foo.bar/ `,
138+
`http://-error-.invalid/ `,
139+
`http://-a.b.co`,
140+
`http://a.b-.co`,
141+
`http://1.1.1.1.1`,
142+
`http://123.123.123`,
143+
`http://3628126748 `,
144+
`http://.www.foo.bar/`,
145+
`http://www.foo.bar./`,
146+
`http://.www.foo.bar./ `,
147+
`http://foo.com/blah_blah_(wikipedia)`,
148+
`http://foo.com/blah_blah_(wikipedia)_(again)`,
149+
`http://✪df.ws/123 `,
150+
`http://userid:password@example.com:8080 `,
151+
`http://userid:password@example.com:8080/`,
152+
`http://userid@example.com `,
153+
`http://userid:password@example.com`,
154+
`http://⌘.ws `,
155+
`http://foo.com/blah_(wikipedia)#cite-1`,
156+
`http://foo.com/unicode_(✪)_in_parens`,
157+
`http://foo.com/(something)?after=parens `,
158+
`http://☺.damowmow.com/`,
159+
`http://code.google.com/events/#&product=browser `,
160+
`ftp://foo.bar/baz `,
161+
`http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com`,
162+
`https://foo_bar.example.com/`
163+
];
164+
165+
const regExpUrl = new RegExp(component.pattern);
166+
167+
urls.forEach(url => {
168+
expect(regExpUrl.test(url)).toBeFalsy(`URL ${url} is a valid URL.`);
169+
});
170+
}));
171+
87172
});
88173

89174
describe('Templates:', () => {
@@ -141,6 +226,36 @@ describe('PoUrlComponent:', () => {
141226
expect(fixture.debugElement.nativeElement.querySelector('.po-field-optional')).toBeNull();
142227
});
143228

229+
it('url: should be valid and have `ng-valid`', fakeAsync(() => {
230+
component.ngAfterViewInit();
231+
tick(200);
232+
233+
const input = component.inputEl.nativeElement;
234+
const fakeURL = 'http://foo.com/blah_blah/';
235+
input.value = fakeURL;
236+
input.dispatchEvent(eventKeyup);
237+
238+
fixture.detectChanges();
239+
240+
expect(input.value).toContain(fakeURL);
241+
expect(fixture.debugElement.nativeElement.querySelectorAll('po-url.ng-dirty.ng-valid')).toBeTruthy();
242+
}));
243+
244+
it('url: should be invalid and have `ng-invalid`', fakeAsync(() => {
245+
component.ngAfterViewInit();
246+
tick(200);
247+
248+
const input = component.inputEl.nativeElement;
249+
const fakeURL = 'http://';
250+
input.value = fakeURL;
251+
input.dispatchEvent(eventKeyup);
252+
253+
fixture.detectChanges();
254+
255+
expect(input.value).toContain(fakeURL);
256+
expect(fixture.debugElement.nativeElement.querySelectorAll('po-url.ng-dirty.ng-invalid')).toBeTruthy();
257+
}));
258+
144259
});
145260

146261
});

projects/ui/src/lib/components/po-field/po-url/po-url.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ export class PoUrlComponent extends PoInputGeneric implements AfterViewInit, OnD
5454
pattern = '^((https|http):\\/\\/)?' + // protocol
5555
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
5656
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
57-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
58-
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
59-
'(\\#[-a-z\\d_]*)?$';
57+
'(\\:\\d+)?(\\/[-A-Za-z\\d%_.~+]*)*' + // port and path
58+
'(\\?[;&A-Za-z\\d%_.~+=-]*)?' + // query string
59+
'(\\#[-A-Za-z\\d_]*)?$';
6060

6161
mask = '';
6262

0 commit comments

Comments
 (0)