From cefab5f47f49a40f844b9ce5a23ce7a6eef5251a Mon Sep 17 00:00:00 2001 From: Philipp Rudloff Date: Thu, 21 Mar 2019 14:51:37 +0100 Subject: [PATCH] Fix appFlexCopy improperly trimming newlines and spaces (#31) --- src/angular/directives/flex-copy.directive.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/angular/directives/flex-copy.directive.ts b/src/angular/directives/flex-copy.directive.ts index 5b8636f0ab..e5e700dbba 100644 --- a/src/angular/directives/flex-copy.directive.ts +++ b/src/angular/directives/flex-copy.directive.ts @@ -21,7 +21,13 @@ export class FlexCopyDirective { for (let i = 0; i < selection.rangeCount; i++) { const range = selection.getRangeAt(i); const text = range.toString(); - copyText += text; + + // The selection should only contain one line of text. In some cases however, the + // selection contains newlines and space characters from the identation of following + // sibling nodes. To avoid copying passwords containing trailing newlines and spaces + // that aren’t part of the password, the selection has to be trimmed. + const stringEndPos = text.includes('\n') ? text.search(/\r?\n/) : text.length; + copyText += text.substring(0, stringEndPos); } this.platformUtilsService.copyToClipboard(copyText, { window: window }); }