Skip to content

Commit e0ce362

Browse files
committed
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 73c6af2 commit e0ce362

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/components/SubscriptionsList.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@
112112
<i class="el-icon-warning-outline"></i>
113113
</a>
114114
</el-tooltip>
115-
<el-input v-model.trim="subRecord.topic" type="textarea" placeholder="testtopic/#" size="small">
115+
<el-input
116+
v-model.trim="subRecord.topic"
117+
type="textarea"
118+
placeholder="testtopic/#"
119+
size="small"
120+
@keydown.enter.native.prevent
121+
@keyup.enter.native.prevent
122+
>
116123
</el-input>
117124
</el-form-item>
118125
</el-col>
@@ -149,7 +156,14 @@
149156
<i class="el-icon-warning-outline"></i>
150157
</a>
151158
</el-tooltip>
152-
<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>
153167
</el-form-item>
154168
</el-col>
155169
<!-- MQTT 5.0 -->
@@ -347,6 +361,8 @@ export default class SubscriptionsList extends Vue {
347361
348362
private saveSubs(): void | boolean {
349363
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, '') || ''
350366
const form = this.getSubForm()
351367
form.validate(async (valid: boolean) => {
352368
if (!valid) {

web/src/components/SubscriptionsList.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@
101101
<i class="el-icon-warning-outline"></i>
102102
</a>
103103
</el-tooltip>
104-
<el-input v-model.trim="subRecord.topic" type="textarea" placeholder="testtopic/#" size="small">
104+
<el-input
105+
v-model.trim="subRecord.topic"
106+
type="textarea"
107+
placeholder="testtopic/#"
108+
size="small"
109+
@keydown.enter.native.prevent
110+
@keyup.enter.native.prevent
111+
>
105112
</el-input>
106113
</el-form-item>
107114
</el-col>
@@ -138,7 +145,14 @@
138145
<i class="el-icon-warning-outline"></i>
139146
</a>
140147
</el-tooltip>
141-
<el-input v-model.trim="subRecord.alias" type="textarea" size="small"> </el-input>
148+
<el-input
149+
v-model.trim="subRecord.alias"
150+
type="textarea"
151+
size="small"
152+
@keydown.enter.native.prevent
153+
@keyup.enter.native.prevent
154+
>
155+
</el-input>
142156
</el-form-item>
143157
</el-col>
144158
<!-- MQTT 5.0 -->
@@ -313,6 +327,8 @@ export default class SubscriptionsList extends Vue {
313327
314328
private saveSubs(): void | boolean {
315329
this.getCurrentConnection(this.connectionId)
330+
this.subRecord.topic = this.subRecord.topic.replace(/[\r\n]+/g, '')
331+
this.subRecord.alias = this.subRecord.alias?.replace(/[\r\n]+/g, '') || ''
316332
if (!this.client || !this.client.connected) {
317333
this.$message.warning(this.$tc('connections.notConnect'))
318334
return false

0 commit comments

Comments
 (0)