aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-23 10:22:22 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-26 18:31:21 +0000
commit357af41d7e8889efb369deb7c61def5efd89b12e (patch)
tree210863b0a53573b2028d638ca71bab110ac836b7
parentselection: unbreak text/uri-list decoding: we’re not using \r, not \n (diff)
selection: strip non-formatting C0, BS, HT and DEL from pasted text
-rw-r--r--CHANGELOG.md2
-rw-r--r--selection.c17
2 files changed, 19 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d8206323..fd01e737 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,8 @@
* Extending a word/line-wise selection now uses the original selection
mode instead of switching to character-wise.
* The scrollback search box no longer accepts non-printable characters.
+* Non-formatting C0 control characters, `BS`, `HT` and `DEL` are now
+ stripped from pasted text.
### Deprecated
diff --git a/selection.c b/selection.c
index 5bf715fe..8b13d2ad 100644
--- a/selection.c
+++ b/selection.c
@@ -1612,6 +1612,7 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
* Call cb while at same time replace:
* - \r\n -> \r
* - \n -> \r
+ * - C0 -> <nothing> (stript non-formatting C0 characters)
* - \e -> <nothing> (i.e. strip ESC)
*/
char *p = text;
@@ -1627,6 +1628,7 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
break;
case '\r':
+ /* Convert \r\n -> \r */
if (i + 1 < left && p[i + 1] == '\n') {
ctx->decoder(ctx, p, i + 1);
@@ -1637,6 +1639,21 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
}
break;
+ /* C0 non-formatting control characters (\b \t \n \r excluded) */
+ case '\x01': case '\x02': case '\x03': case '\x04': case '\x05':
+ case '\x06': case '\x07': case '\x0b': case '\x0c': case '\x0e':
+ case '\x0f': case '\x10': case '\x11': case '\x12': case '\x13':
+ case '\x14': case '\x15': case '\x16': case '\x17': case '\x18':
+ case '\x19': case '\x1a': case '\x1b': case '\x1c': case '\x1d':
+ case '\x1e': case '\x1f':
+ /* FALLTHROUGH */
+
+ /* Additional control characters stripped by default (but
+ * configurable) in XTerm: BS, HT, DEL */
+ case '\b': case '\t': case '\x1f':
+ /* FALLTHROUGH */
+
+ /* ESC */
case '\x1b':
ctx->decoder(ctx, p, i);