Skip to content

Commit 5a7c0d2

Browse files
authored
Merge pull request #147 from cabal-club/sanitize-usernames
sanitize usernames across the cli
2 parents ba2fb38 + 3062478 commit 5a7c0d2

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Commander (view, client) {
3434
call: (arg) => {
3535
if (arg === '') return
3636
this.cabal.publishNick(arg)
37-
this.view.writeLine("* you're now known as " + arg)
37+
this.view.writeLine("* you're now known as " + util.sanitizeString(arg))
3838
}
3939
},
4040
emote: {
@@ -57,7 +57,7 @@ function Commander (view, client) {
5757
var userkeys = Object.keys(users).map((key) => users[key]).sort(util.cmpUser)
5858
logToView('* history of peers in this cabal')
5959
userkeys.map((u) => {
60-
var username = u.name || 'conspirator'
60+
var username = util.sanitizeString(u.name) || 'conspirator'
6161
var spaces = ' '.repeat(15)
6262
var paddedName = (username + spaces).slice(0, spaces.length)
6363
logToView(` ${paddedName} ${u.key}`)

neat-screen.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,14 @@ NeatScreen.prototype.formatMessage = function (msg) {
410410
const users = this.client.getUsers()
411411
const authorSource = users[msg.key] || msg
412412

413-
const author = authorSource.name || authorSource.key.slice(0, 8)
413+
const author = util.sanitizeString(authorSource.name || authorSource.key.slice(0, 8))
414414
// add author field for later use in calculating the left-padding of multi-line messages
415415
msg.author = author
416416
var localNick = 'uninitialized'
417417
if (this.state) { localNick = this.state.cabal.getLocalName() }
418-
/* sanitize input to prevent interface from breaking */
418+
419+
/* sanitize user inputs to prevent interface from breaking */
420+
localNick = util.sanitizeString(localNick)
419421
var msgtxt = msg.value.content.text
420422
if (msg.value.type !== 'status') {
421423
msgtxt = util.sanitizeString(msgtxt)

views.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function linkSize (state) {
8383
}
8484

8585
function renderPrompt (state) {
86-
var name = state.cabal ? state.cabal.getLocalName() : 'unknown'
86+
var name = util.sanitizeString(state.cabal ? state.cabal.getLocalName() : 'unknown')
8787
return [
8888
`[${chalk.cyan(name)}:${state.cabal.getCurrentChannel()}] ${state.neat.input.line()}`
8989
]
@@ -156,7 +156,7 @@ function renderNicks (state, width, height) {
156156
users = users
157157
.map(function (user) {
158158
var name = ''
159-
if (user && user.name) name += user.name.slice(0, width)
159+
if (user && user.name) name += util.sanitizeString(user.name).slice(0, width)
160160
else name += user.key.slice(0, Math.min(8, width))
161161
if (user.online) { onlines[name] = name in onlines ? onlines[name] + 1 : 1 }
162162
return name

0 commit comments

Comments
 (0)