add _encodeDriveLetterColon to toString #61504

This commit is contained in:
Johannes Rieken
2018-10-22 18:49:57 +02:00
parent 11cb54e1a9
commit c537eaa147
3 changed files with 18 additions and 9 deletions
+8 -8
View File
@@ -346,8 +346,8 @@ export class URI implements UriComponents {
*
* @param skipEncoding Do not encode the result, default is `false`
*/
public toString(skipEncoding: boolean = false): string {
return _asFormatted(this, skipEncoding);
public toString(skipEncoding: boolean = false, _encodeDriveLetterColon: boolean = false): string {
return _asFormatted(this, skipEncoding, _encodeDriveLetterColon);
}
public toJSON(): object {
@@ -398,15 +398,15 @@ class _URI extends URI {
return this._fsPath;
}
public toString(skipEncoding: boolean = false): string {
if (!skipEncoding) {
toString(skipEncoding: boolean = false, _encodeDriveLetterColon: boolean = false): string {
if (!skipEncoding && !_encodeDriveLetterColon) {
if (!this._formatted) {
this._formatted = _asFormatted(this, false);
this._formatted = _asFormatted(this, false, _encodeDriveLetterColon);
}
return this._formatted;
} else {
// we don't cache that
return _asFormatted(this, true);
return _asFormatted(this, true, _encodeDriveLetterColon);
}
}
@@ -575,7 +575,7 @@ function _makeFsPath(uri: URI): string {
/**
* Create the external version of a uri
*/
function _asFormatted(uri: URI, skipEncoding: boolean): string {
function _asFormatted(uri: URI, skipEncoding: boolean, encodeDriveLetterColon: boolean): string {
const encoder = !skipEncoding
? encodeURIComponentFast
@@ -639,7 +639,7 @@ function _asFormatted(uri: URI, skipEncoding: boolean): string {
encodeOffset = 2;
}
}
if (scheme !== 'file' || path.length > encodeOffset && path.charCodeAt(encodeOffset) !== CharCode.Slash) {
if (scheme !== 'file' || encodeDriveLetterColon || path.length > encodeOffset && path.charCodeAt(encodeOffset) !== CharCode.Slash) {
encodeOffset = 0;
}
+9
View File
@@ -490,4 +490,13 @@ suite('URI', () => {
});
test('Storage: workspace identifier changed (URI.toString()) #61504', function () {
if (isWindows) {
const uri = URI.file('c:\\Users\\bpasero\\Desktop\\Golda\'s Kitchen\\CHANGELOG.md');
assert.ok(uri.toString().indexOf('%3A') < 0);
assert.ok(uri.toString(false, false).indexOf('%3A') < 0);
assert.ok(uri.toString(false, true).indexOf('%3A') > 0);
}
});
});
+1 -1
View File
@@ -192,7 +192,7 @@ declare namespace monaco {
*
* @param skipEncoding Do not encode the result, default is `false`
*/
toString(skipEncoding?: boolean): string;
toString(skipEncoding?: boolean, _encodeDriveLetterColon?: boolean): string;
toJSON(): object;
static revive(data: UriComponents | any): Uri;
}