Skip to content

Commit

Permalink
Fix oppia#20153: Trim whitespace at beginning and end of input text t…
Browse files Browse the repository at this point in the history
…o prevent duplicate options being saved (oppia#20685)

* Add function to trim whitespace at beginning and end of input text

* fix syntax

* fix syntax
  • Loading branch information
raafeahmed authored Jul 23, 2024
1 parent 535b0c7 commit 79e6d0a
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ export class CkEditor4RteComponent
break;
}
}
textElt.forEach(node => this.trimTextNodes(node));
let html = elt.html();
this.value = html;
// Refer to the note at the top of the file for the reason behind replace.
Expand Down Expand Up @@ -586,6 +587,14 @@ export class CkEditor4RteComponent
this.ck.destroy();
this.subscriptions.unsubscribe();
}

trimTextNodes(node: Node): void {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.trim();
} else {
node.childNodes.forEach(child => this.trimTextNodes(child));
}
}
}

angular.module('oppia').directive(
Expand Down

0 comments on commit 79e6d0a

Please sign in to comment.