-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect and modify invalid URL characters (#1664)
* feat: added invalid URL detection for snapshot & network urls * test: added test for snapshot urls for detecting snapshot url * test: added test for network urls * test: test fix * test: snapshot.test.js fix * test: coverage fix * test: coverage fix * fix: addressing comment feat: moved logging and trycatch handling to utils.js chore: Updated error/warning message for invalid URL's * test: test fix on assets discovery * test: added test for utils.js(decodeAndEncodeURLWithLogging) * chore: addressing comments, moving to function validateAndFixSnapshotUrl in snapshot.js * chore: lint fix
- Loading branch information
1 parent
ed3868d
commit a555427
Showing
6 changed files
with
239 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { decodeAndEncodeURLWithLogging } from '../src/utils.js'; | ||
import { logger } from './helpers/index.js'; | ||
import percyLogger from '@percy/logger'; | ||
|
||
describe('utils', () => { | ||
let log; | ||
beforeEach(async () => { | ||
log = percyLogger(); | ||
logger.reset(true); | ||
await logger.mock({ level: 'debug' }); | ||
}); | ||
|
||
describe('decodeAndEncodeURLWithLogging', () => { | ||
it('does not warn invalid url when options params is null', async () => { | ||
decodeAndEncodeURLWithLogging('https://abc.com/test%abc', log); | ||
expect(logger.stderr).toEqual([]); | ||
}); | ||
|
||
it('does not warn invalid url when shouldLogWarning = false', async () => { | ||
decodeAndEncodeURLWithLogging('https://abc.com/test%abc', log, | ||
{ | ||
shouldLogWarning: false | ||
}); | ||
|
||
expect(logger.stderr).toEqual([]); | ||
}); | ||
|
||
it('returns modified url', async () => { | ||
const url = decodeAndEncodeURLWithLogging('https://abc.com/test[ab]c', log, | ||
{ | ||
shouldLogWarning: false | ||
}); | ||
expect(logger.stderr).toEqual([]); | ||
expect(url).toEqual('https://abc.com/test%5Bab%5Dc'); | ||
}); | ||
|
||
it('warns if invalid url when shouldLogWarning = true', async () => { | ||
decodeAndEncodeURLWithLogging( | ||
'https://abc.com/test%abc', | ||
log, | ||
{ | ||
shouldLogWarning: true, | ||
warningMessage: 'some Warning Message' | ||
}); | ||
expect(logger.stderr).toEqual(['[percy] some Warning Message']); | ||
}); | ||
}); | ||
}); |