-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: local refs should not contain any whitespace characters (#89)
* fix: local refs should not contain any whitespace characters * chore: # edge case and tests * fix: make regex less strict
- Loading branch information
Showing
2 changed files
with
32 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
import { isLocalRef } from '../isLocalRef'; | ||
|
||
describe('isLocalRef', () => { | ||
it.each(['#', '#/', '#/foo', '#/0/1', '#/~1'])('should treat %s as local reference', ref => { | ||
it.each([ | ||
'#', | ||
'#/foo', | ||
'#/foo/0', | ||
'#/', | ||
'#/a~1b', | ||
'#/c%25d', | ||
'#/e%5Ef', | ||
'#/g%7Ch', | ||
'#/i%5Cj', | ||
'#/k%22l', | ||
'#/%20', | ||
'#/m~0n', | ||
'#./d~8z', | ||
])('should treat %s as local reference', ref => { | ||
expect(isLocalRef(ref)).toEqual(true); | ||
}); | ||
|
||
it.each(['', '../#', 'http://a#', '/foo/#', '../test.yaml#/'])('should not treat %s as local reference', ref => { | ||
expect(isLocalRef(ref)).toEqual(false); | ||
it.each([ | ||
'', | ||
'../#', | ||
'http://a#', | ||
'/foo/#', | ||
'../test.yaml#/', | ||
'#/foo\n/bar', | ||
'#/foo\t/bar', | ||
'#/foo\u2006/bar', | ||
' #/foo/bar', | ||
'#/foo /bar', | ||
'#/foo/bar ', | ||
'# Hello, world!', | ||
'foo', | ||
])('should not treat %s as local reference', ref => { | ||
expect(isLocalRef(ref as string)).toEqual(false); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export const isLocalRef = (pointer: string) => pointer.length > 0 && pointer[0] === '#'; | ||
export const isLocalRef = (pointer: string) => pointer.length > 0 && (pointer === '#' || /^#\S*$/.test(pointer)); |