diff --git a/src/sql/parts/connection/common/utils.ts b/src/sql/parts/connection/common/utils.ts index 445eac15e7..4a07c63301 100644 --- a/src/sql/parts/connection/common/utils.ts +++ b/src/sql/parts/connection/common/utils.ts @@ -88,19 +88,6 @@ export function parseNumAsTimeString(value: number): string { return tempVal > 0 ? rs + '.' + mss : rs; } -/** - * Converts <, >, &, ", ', and any characters that are outside \u00A0 to numeric HTML entity values - * like { - * (Adapted from http://stackoverflow.com/a/18750001) - * @param str String to convert - * @return String with characters replaced. - */ -export function htmlEntities(str: string): string { - return typeof (str) === 'string' - ? str.replace(/[\u00A0-\u9999<>\&"']/gim, (i) => { return `${i.charCodeAt(0)};`; }) - : undefined; -} - export function generateUri(connection: IConnectionProfile, purpose?: 'dashboard' | 'insights' | 'connection'): string { let prefix = purpose ? uriPrefixes[purpose] : uriPrefixes.default; let uri = generateUriWithPrefix(connection, prefix); diff --git a/src/sql/parts/grid/services/sharedServices.ts b/src/sql/parts/grid/services/sharedServices.ts index 42d96d20de..c02292730a 100644 --- a/src/sql/parts/grid/services/sharedServices.ts +++ b/src/sql/parts/grid/services/sharedServices.ts @@ -3,14 +3,14 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as Utils from 'sql/parts/connection/common/utils'; +import * as Strings from 'vs/base/common/strings'; export class DBCellValue { displayValue: string; isNull: boolean; public static isDBCellValue(object: any): boolean { - return (object !== undefined && object.displayValue !== undefined && object.isNull !== undefined); + return (object !== undefined && object.displayValue !== undefined && object.isNull !== undefined); } } @@ -25,7 +25,7 @@ export function hyperLinkFormatter(row: number, cell: any, value: any, columnDef valueToDisplay = 'NULL'; if (!value.isNull) { cellClasses += ' xmlLink'; - valueToDisplay = Utils.htmlEntities(value.displayValue); + valueToDisplay = Strings.escape(value.displayValue); return `${valueToDisplay}`; } else { cellClasses += ' missing-value'; @@ -44,13 +44,12 @@ export function textFormatter(row: number, cell: any, value: any, columnDef: any if (DBCellValue.isDBCellValue(value)) { valueToDisplay = 'NULL'; if (!value.isNull) { - valueToDisplay = Utils.htmlEntities(value.displayValue.replace(/(\r\n|\n|\r)/g, ' ')); + valueToDisplay = Strings.escape(value.displayValue.replace(/(\r\n|\n|\r)/g, ' ')); } else { cellClasses += ' missing-value'; } - } else if (typeof value === 'string'){ - valueToDisplay = value; - + } else if (typeof value === 'string') { + valueToDisplay = Strings.escape(value); } return `${valueToDisplay}`; diff --git a/src/sqltest/parts/grid/services/sharedServices.test.ts b/src/sqltest/parts/grid/services/sharedServices.test.ts new file mode 100644 index 0000000000..ebcee41727 --- /dev/null +++ b/src/sqltest/parts/grid/services/sharedServices.test.ts @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; +import * as sqlops from 'sqlops'; +import * as assert from 'assert'; +import * as SharedServices from 'sql/parts/grid/services/sharedServices'; + +const testText = '