Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
b6dabf73
Commit
b6dabf73
authored
Jun 22, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
muc: Ensure that exact nicknames (and not substrings) are matched
parent
e2fbfa74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
6 deletions
+11
-6
spec/muc_messages.js
spec/muc_messages.js
+7
-2
src/headless/converse-muc.js
src/headless/converse-muc.js
+2
-2
src/headless/utils/parse-helpers.js
src/headless/utils/parse-helpers.js
+2
-2
No files found.
spec/muc_messages.js
View file @
b6dabf73
...
...
@@ -991,7 +991,7 @@ describe("A Groupchat Message", function () {
const
muc_jid
=
'
lounge@montague.lit
'
;
await
mock
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
tom
'
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
muc_jid
);
[
'
z3r0
'
,
'
mr.robot
'
,
'
gibson
'
,
'
sw0rdf1sh
'
,
'
Link Mauve
'
].
forEach
((
nick
)
=>
{
[
'
z3r0
'
,
'
mr.robot
'
,
'
gibson
'
,
'
sw0rdf1sh
'
,
'
Link Mauve
'
,
'
robot
'
].
forEach
((
nick
)
=>
{
_converse
.
connection
.
_dataRecv
(
mock
.
createRequest
(
$pres
({
'
to
'
:
'
tom@montague.lit/resource
'
,
...
...
@@ -1017,7 +1017,12 @@ describe("A Groupchat Message", function () {
await
view
.
model
.
handleMessageStanza
(
stanza
);
// Run a few unit tests for the parseTextForReferences method
let
[
text
,
references
]
=
view
.
model
.
parseTextForReferences
(
'
hello z3r0
'
)
let
[
text
,
references
]
=
view
.
model
.
parseTextForReferences
(
'
yo @robot
'
)
expect
(
text
).
toBe
(
'
yo robot
'
);
expect
(
references
)
.
toEqual
([{
"
begin
"
:
3
,
"
end
"
:
8
,
"
value
"
:
"
robot
"
,
"
type
"
:
"
mention
"
,
"
uri
"
:
"
xmpp:robot@montague.lit
"
}]);
[
text
,
references
]
=
view
.
model
.
parseTextForReferences
(
'
hello z3r0
'
)
expect
(
references
.
length
).
toBe
(
0
);
expect
(
text
).
toBe
(
'
hello z3r0
'
);
...
...
src/headless/converse-muc.js
View file @
b6dabf73
...
...
@@ -965,7 +965,7 @@ converse.plugins.add('converse-muc', {
const
known_nicknames
=
this
.
getAllKnownNicknames
();
const
known_nicknames_with_at_regex
=
this
.
getAllKnownNicknamesRegex
();
const
getMatchesForNickRegex
=
nick_regex
=>
[...
findRegexInMessage
(
nick_regex
)];
const
get
NicknameFromRegex
=
p
.
findFirstMatchInArray
(
known_nicknames
);
const
get
MatchingNickname
=
p
.
findFirstMatchInArray
(
known_nicknames
);
const
uriFromNickname
=
nickname
=>
{
const
jid
=
this
.
get
(
'
jid
'
);
...
...
@@ -978,7 +978,7 @@ converse.plugins.add('converse-muc', {
const
at_sign_index
=
match
[
0
].
indexOf
(
'
@
'
);
const
begin
=
match
.
index
+
at_sign_index
;
const
end
=
begin
+
match
[
0
].
length
-
at_sign_index
;
const
value
=
get
NicknameFromRegex
(
RegExp
(
match
[
1
],
'
i
'
)
);
const
value
=
get
MatchingNickname
(
match
[
1
]
);
const
type
=
'
mention
'
;
const
uri
=
uriFromNickname
(
value
);
return
{
begin
,
end
,
value
,
type
,
uri
}
...
...
src/headless/utils/parse-helpers.js
View file @
b6dabf73
...
...
@@ -19,9 +19,9 @@ helpers.escapeCharacters = characters => string =>
helpers
.
escapeRegexString
=
helpers
.
escapeCharacters
(
'
[
\\
^$.?*+(){}
'
);
// `for` is ~25% faster than using `Array.find()`
helpers
.
findFirstMatchInArray
=
array
=>
regex
=>
{
helpers
.
findFirstMatchInArray
=
array
=>
text
=>
{
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
if
(
regex
.
test
(
array
[
i
])
)
{
if
(
text
.
localeCompare
(
array
[
i
],
undefined
,
{
sensitivity
:
'
base
'
})
===
0
)
{
return
array
[
i
];
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment