Skip to content

Commit 8b3f3ce

Browse files
ysfscreamRed-Asuka
authored andcommitted
fix(subscriptions): prevent newlines in topic and alias textarea inputs
Prevent Enter key from inserting newlines in subscription topic and alias fields, and strip any existing newline characters when saving.
1 parent 45c1ddf commit 8b3f3ce

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/components/SubscriptionsList.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,15 @@
112112
<i class="el-icon-warning-outline"></i>
113113
</a>
114114
</el-tooltip>
115-
<el-input v-model="topicInput" type="textarea" placeholder="testtopic/#" size="small"> </el-input>
115+
<el-input
116+
v-model="topicInput"
117+
type="textarea"
118+
placeholder="testtopic/#"
119+
size="small"
120+
@keydown.enter.native.prevent
121+
@keyup.enter.native.prevent
122+
>
123+
</el-input>
116124
<div v-if="topicHasWhitespace" class="topic-whitespace-hint">
117125
<span class="topic-whitespace-label">{{ $t('connections.topicWhitespaceHint') }}</span>
118126
<span class="topic-whitespace-marker">
@@ -159,7 +167,14 @@
159167
<i class="el-icon-warning-outline"></i>
160168
</a>
161169
</el-tooltip>
162-
<el-input v-model.trim="subRecord.alias" type="textarea" size="small"> </el-input>
170+
<el-input
171+
v-model.trim="subRecord.alias"
172+
type="textarea"
173+
size="small"
174+
@keydown.enter.native.prevent
175+
@keyup.enter.native.prevent
176+
>
177+
</el-input>
163178
</el-form-item>
164179
</el-col>
165180
<!-- MQTT 5.0 -->
@@ -380,6 +395,8 @@ export default class SubscriptionsList extends Vue {
380395
381396
private saveSubs(): void | boolean {
382397
this.getCurrentConnection(this.connectionId)
398+
this.subRecord.topic = this.subRecord.topic.replace(/[\r\n]+/g, '')
399+
this.subRecord.alias = this.subRecord.alias?.replace(/[\r\n]+/g, '') || ''
383400
const form = this.getSubForm()
384401
form.validate(async (valid: boolean) => {
385402
if (!valid) {

web/src/components/SubscriptionsList.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,15 @@
101101
<i class="el-icon-warning-outline"></i>
102102
</a>
103103
</el-tooltip>
104-
<el-input v-model="topicInput" type="textarea" placeholder="testtopic/#" size="small"> </el-input>
104+
<el-input
105+
v-model="topicInput"
106+
type="textarea"
107+
placeholder="testtopic/#"
108+
size="small"
109+
@keydown.enter.native.prevent
110+
@keyup.enter.native.prevent
111+
>
112+
</el-input>
105113
<div v-if="topicHasWhitespace" class="topic-whitespace-hint">
106114
<span class="topic-whitespace-label">{{ $t('connections.topicWhitespaceHint') }}</span>
107115
<span class="topic-whitespace-marker">
@@ -148,7 +156,14 @@
148156
<i class="el-icon-warning-outline"></i>
149157
</a>
150158
</el-tooltip>
151-
<el-input v-model.trim="subRecord.alias" type="textarea" size="small"> </el-input>
159+
<el-input
160+
v-model.trim="subRecord.alias"
161+
type="textarea"
162+
size="small"
163+
@keydown.enter.native.prevent
164+
@keyup.enter.native.prevent
165+
>
166+
</el-input>
152167
</el-form-item>
153168
</el-col>
154169
<!-- MQTT 5.0 -->
@@ -346,6 +361,8 @@ export default class SubscriptionsList extends Vue {
346361
347362
private saveSubs(): void | boolean {
348363
this.getCurrentConnection(this.connectionId)
364+
this.subRecord.topic = this.subRecord.topic.replace(/[\r\n]+/g, '')
365+
this.subRecord.alias = this.subRecord.alias?.replace(/[\r\n]+/g, '') || ''
349366
if (!this.client || !this.client.connected) {
350367
this.$message.warning(this.$tc('connections.notConnect'))
351368
return false

0 commit comments

Comments
 (0)