Commit 5db51d8 1 parent 5929a46 commit 5db51d8 Copy full SHA for 5db51d8
File tree 2 files changed +64
-3
lines changed
2 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,9 @@ export function resolve(from: string, to: string) {
31
31
if ( resolvedUrl . protocol === "resolve:" ) {
32
32
// `from` is a relative URL.
33
33
const { pathname, search, hash } = resolvedUrl ;
34
- return pathname + search + hash ;
34
+ const endSpaces = to . match ( / ( \s * ) $ / ) ?. [ 1 ] || "" ;
35
+
36
+ return pathname + search + hash + endSpaces ;
35
37
}
36
38
return resolvedUrl . toString ( ) ;
37
39
}
@@ -105,7 +107,10 @@ export function stripQuery(path: any) {
105
107
* @param path
106
108
* @returns
107
109
*/
108
- export function getHash ( path : string ) {
110
+ export function getHash ( path : undefined | string ) {
111
+ if ( ! path ) {
112
+ return "#" ;
113
+ }
109
114
const hashIndex = path . indexOf ( "#" ) ;
110
115
if ( hashIndex >= 0 ) {
111
116
return path . substring ( hashIndex ) ;
@@ -119,7 +124,10 @@ export function getHash(path: string) {
119
124
* @param path
120
125
* @returns
121
126
*/
122
- export function stripHash ( path : string ) {
127
+ export function stripHash ( path ?: string | undefined ) {
128
+ if ( ! path ) {
129
+ return "" ;
130
+ }
123
131
const hashIndex = path . indexOf ( "#" ) ;
124
132
if ( hashIndex >= 0 ) {
125
133
path = path . substring ( 0 , hashIndex ) ;
Original file line number Diff line number Diff line change @@ -21,4 +21,57 @@ describe("$refs that include slashes", () => {
21
21
} ,
22
22
} ) ;
23
23
} ) ;
24
+
25
+ it ( "should parse trailing spaces successfully" , async ( ) => {
26
+ const parser = new $RefParser ( ) ;
27
+ const derefed = await parser . dereference ( {
28
+ swagger : "2.0" ,
29
+ paths : {
30
+ somepath : {
31
+ post : {
32
+ $ref : "#/definitions/ABC " ,
33
+ } ,
34
+ } ,
35
+ } ,
36
+ definitions : {
37
+ "ABC " : {
38
+ // tested removing space at the end of "ABC "
39
+ type : "object" ,
40
+ properties : {
41
+ abc : {
42
+ type : "string" ,
43
+ } ,
44
+ } ,
45
+ title : "ABC " ,
46
+ } ,
47
+ } ,
48
+ } ) ;
49
+ expect ( derefed ) . to . deep . equal ( {
50
+ swagger : "2.0" ,
51
+ paths : {
52
+ somepath : {
53
+ post : {
54
+ type : "object" ,
55
+ properties : {
56
+ abc : {
57
+ type : "string" ,
58
+ } ,
59
+ } ,
60
+ title : "ABC " ,
61
+ } ,
62
+ } ,
63
+ } ,
64
+ definitions : {
65
+ "ABC " : {
66
+ type : "object" ,
67
+ properties : {
68
+ abc : {
69
+ type : "string" ,
70
+ } ,
71
+ } ,
72
+ title : "ABC " ,
73
+ } ,
74
+ } ,
75
+ } ) ;
76
+ } ) ;
24
77
} ) ;
You can’t perform that action at this time.
0 commit comments