File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -653,14 +653,14 @@ export class Filelink {
653
653
654
654
if ( this . b64 ) {
655
655
if ( this . transforms . length > 0 ) {
656
- transformsString = `b64/${ b64 ( JSON . stringify ( this . transforms ) ) } ` ;
656
+ transformsString = `b64/${ b64 ( JSON . stringify ( this . transforms ) , true ) } ` ;
657
657
}
658
658
659
659
if ( Array . isArray ( source ) ) {
660
660
source = this . arrayToString ( source ) ;
661
661
}
662
662
663
- source = `b64://${ b64 ( source ) } ` ;
663
+ source = `b64://${ b64 ( source , true ) } ` ;
664
664
} else {
665
665
if ( Array . isArray ( source ) ) {
666
666
source = this . arrayToString ( source ) ;
Original file line number Diff line number Diff line change @@ -107,6 +107,14 @@ describe('utils:index', () => {
107
107
it ( 'should return correct b65 value' , ( ) => {
108
108
expect ( b64 ( 'testtext' ) ) . toEqual ( 'dGVzdHRleHQ=' ) ;
109
109
} ) ;
110
+
111
+ it ( 'should escape chars to make b64 url safe string - char "/"' , ( ) => {
112
+ expect ( b64 ( '*0eijATh#"I$PR)s<uTa}{t>E"LC:L' , true ) ) . toEqual ( 'KjBlaWpBVGgjIkkkUFIpczx1VGF9e3Q-RSJMQzpM' ) ;
113
+ } ) ;
114
+
115
+ it ( 'should escape chars to make b64 url safe string - char ""' , ( ) => {
116
+ expect ( b64 ( 'W{wpB@ckYD0O@&?!||9PS)7^+F*H8N' , true ) ) . toEqual ( 'V3t3cEJAY2tZRDBPQCY_IXx8OVBTKTdeK0YqSDhO' ) ;
117
+ } ) ;
110
118
} ) ;
111
119
112
120
describe ( 'sanitizeName' , ( ) => {
Original file line number Diff line number Diff line change @@ -164,12 +164,20 @@ export const getMimetype = (file: Uint8Array | Buffer): string => {
164
164
* return based string
165
165
* @param data
166
166
*/
167
- export const b64 = ( data : string ) : string => {
167
+ export const b64 = ( data : string , safeUrl : boolean = false ) : string => {
168
+ let b64 ;
169
+
168
170
if ( isNode ( ) ) {
169
- return Buffer . from ( data ) . toString ( 'base64' ) ;
171
+ b64 = Buffer . from ( data ) . toString ( 'base64' ) ;
172
+ } else {
173
+ b64 = btoa ( data ) ;
174
+ }
175
+
176
+ if ( safeUrl ) {
177
+ return b64 . replace ( / \/ / g, '_' ) . replace ( / \+ / g, '-' ) ;
170
178
}
171
179
172
- return btoa ( data ) ;
180
+ return b64 ;
173
181
} ;
174
182
175
183
/**
You can’t perform that action at this time.
0 commit comments