Skip to content

Commit 2139798

Browse files
authored
Fix copy/paste of unicode results on Mac (#1067)
1 parent b1bcd28 commit 2139798

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/controllers/queryRunner.ts

+8
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,15 @@ export default class QueryRunner {
335335
p = p.then(tasks[i]);
336336
}
337337
p.then(() => {
338+
let oldLang: string;
339+
if (process.platform === 'darwin') {
340+
oldLang = process.env['LANG'];
341+
process.env['LANG'] = 'en_US.UTF-8';
342+
}
338343
ncp.copy(copyString, () => {
344+
if (process.platform === 'darwin') {
345+
process.env['LANG'] = oldLang;
346+
}
339347
resolve();
340348
});
341349
});

test/queryRunner.test.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ suite('Query Runner tests', () => {
504504
'3' + TAB + '4' + CLRF +
505505
'5' + TAB + '6' + CLRF +
506506
'7' + TAB + '8' + CLRF +
507-
'9' + TAB + '10';
507+
'9' + TAB + '10';
508508

509509
const finalStringWithHeader = 'Col1' + TAB + 'Col2' + CLRF + finalStringNoHeader;
510510

@@ -517,10 +517,11 @@ suite('Query Runner tests', () => {
517517
[{isNull: false, displayValue: '3'}, {isNull: false, displayValue: '4'}],
518518
[{isNull: false, displayValue: '5'}, {isNull: false, displayValue: '6'}],
519519
[{isNull: false, displayValue: '7'}, {isNull: false, displayValue: '8'}],
520-
[{isNull: false, displayValue: '9'}, {isNull: false, displayValue: '10'}]
520+
[{isNull: false, displayValue: '9'}, {isNull: false, displayValue: '10'}]
521521
]
522522
}
523523
};
524+
process.env['LANG'] = 'C';
524525

525526
let testRange: ISlickRange[] = [{fromCell: 0, fromRow: 0, toCell: 1, toRow: 4}];
526527

@@ -570,7 +571,7 @@ suite('Query Runner tests', () => {
570571
);
571572
queryRunner.uri = testuri;
572573
return queryRunner.copyResults(testRange, 0, 0).then(() => {
573-
let pasteContents = ncp.paste();
574+
let pasteContents = pasteCopiedString();
574575
assert.equal(pasteContents, finalStringNoHeader);
575576
});
576577
});
@@ -593,7 +594,7 @@ suite('Query Runner tests', () => {
593594
// Call handleResult to ensure column header info is seeded
594595
queryRunner.handleQueryComplete(result);
595596
return queryRunner.copyResults(testRange, 0, 0).then(() => {
596-
let pasteContents = ncp.paste();
597+
let pasteContents = pasteCopiedString();
597598
assert.equal(pasteContents, finalStringWithHeader);
598599
});
599600
});
@@ -618,7 +619,7 @@ suite('Query Runner tests', () => {
618619

619620
// call copyResults with additional parameter indicating to include headers
620621
return queryRunner.copyResults(testRange, 0, 0, true).then(() => {
621-
let pasteContents = ncp.paste();
622+
let pasteContents = pasteCopiedString();
622623
assert.equal(pasteContents, finalStringWithHeader);
623624
});
624625
});
@@ -643,7 +644,7 @@ suite('Query Runner tests', () => {
643644

644645
// call copyResults with additional parameter indicating to not include headers
645646
return queryRunner.copyResults(testRange, 0, 0, false).then(() => {
646-
let pasteContents = ncp.paste();
647+
let pasteContents = pasteCopiedString();
647648
assert.equal(pasteContents, finalStringNoHeader);
648649
});
649650
});
@@ -676,3 +677,16 @@ function setupStandardQueryNotificationHandlerMock(testQueryNotificationHandler:
676677
assert.equal(u, standardUri);
677678
});
678679
}
680+
681+
function pasteCopiedString(): string {
682+
let oldLang: string;
683+
if (process.platform === 'darwin') {
684+
oldLang = process.env['LANG'];
685+
process.env['LANG'] = 'en_US.UTF-8';
686+
}
687+
let pastedString = ncp.paste();
688+
if (process.platform === 'darwin') {
689+
process.env['LANG'] = oldLang;
690+
}
691+
return pastedString;
692+
}

0 commit comments

Comments
 (0)