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
3535d05f
Commit
3535d05f
authored
Aug 27, 2020
by
Ariel Fuggini
Committed by
JC Brand
Sep 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes query params from urls as set in config
parent
d83d0158
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
3 deletions
+42
-3
docs/source/configuration.rst
docs/source/configuration.rst
+7
-0
spec/messages.js
spec/messages.js
+23
-0
src/converse-chatview.js
src/converse-chatview.js
+1
-0
src/templates/directives/body.js
src/templates/directives/body.js
+4
-3
src/utils/html.js
src/utils/html.js
+7
-0
No files found.
docs/source/configuration.rst
View file @
3535d05f
...
...
@@ -836,6 +836,13 @@ Before version 1.0.3 Converse would ignore received messages if they were
intended for a different resource then the current user had. It was decided to
drop this restriction but leave it configurable.
filter_url_query_params
-----------------------
* Default: ``null``
Accepts a string or array of strings. Any query strings from URLs that match this setting will be removed.
fullname
--------
...
...
spec/messages.js
View file @
3535d05f
...
...
@@ -896,6 +896,29 @@ describe("A Chat Message", function () {
done
();
}));
it
(
"
will remove url query parameters from hyperlinks as set
"
,
mock
.
initConverse
(
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
await
mock
.
waitForRoster
(
_converse
,
'
current
'
);
await
mock
.
openControlBox
(
_converse
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@montague.lit
'
;
await
mock
.
openChatBoxFor
(
_converse
,
contact_jid
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
contact_jid
);
_converse
.
api
.
settings
.
set
(
'
filter_url_query_params
'
,
[
'
utm_medium
'
,
'
utm_content
'
,
'
s
'
]);
const
message
=
'
This message contains a hyperlink with forbidden query params: https://www.opkode.com/?id=0&utm_content=1&utm_medium=2&s=1
'
;
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
mock
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
await
new
Promise
(
resolve
=>
view
.
model
.
messages
.
once
(
'
rendered
'
,
resolve
));
const
msg
=
sizzle
(
'
.chat-content .chat-msg:last .chat-msg__text
'
,
view
.
el
).
pop
();
expect
(
msg
.
textContent
).
toEqual
(
message
);
await
u
.
waitUntil
(()
=>
msg
.
innerHTML
.
replace
(
/<!---->/g
,
''
)
===
'
This message contains a hyperlink with forbidden query params: <a target="_blank" rel="noopener" href="https://www.opkode.com/?id=0">https://www.opkode.com/?id=0</a>
'
);
done
();
}));
it
(
"
will render newlines
"
,
mock
.
initConverse
(
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
...
...
src/converse-chatview.js
View file @
3535d05f
...
...
@@ -52,6 +52,7 @@ converse.plugins.add('converse-chatview', {
api
.
settings
.
extend
({
'
auto_focus
'
:
true
,
'
debounced_content_rendering
'
:
true
,
'
filter_url_query_params
'
:
null
,
'
image_urls_regex
'
:
null
,
'
message_limit
'
:
0
,
'
muc_hats_from_vcard
'
:
false
,
...
...
src/templates/directives/body.js
View file @
3535d05f
...
...
@@ -117,12 +117,13 @@ function addHyperlinks (text, onImgLoad, onImgClick) {
const
show_images
=
api
.
settings
.
get
(
'
show_images_inline
'
);
objs
.
forEach
(
url_obj
=>
{
const
url_text
=
text
.
slice
(
url_obj
.
start
,
url_obj
.
end
);
const
filtered_url
=
u
.
filterQueryParamsFromURL
(
url_text
);
text
.
addTemplateResult
(
url_obj
.
start
,
url_obj
.
end
,
show_images
&&
u
.
isImageURL
(
url_text
)
&&
u
.
isImageDomainAllowed
(
url_text
)
?
u
.
convertToImageTag
(
url_text
,
onImgLoad
,
onImgClick
)
:
u
.
convertUrlToHyperlink
(
url_text
)
show_images
&&
u
.
isImageURL
(
url_text
)
&&
u
.
isImageDomainAllowed
(
url_text
)
?
u
.
convertToImageTag
(
filtered_url
,
onImgLoad
,
onImgClick
)
:
u
.
convertUrlToHyperlink
(
filtered_url
),
);
});
}
...
...
src/utils/html.js
View file @
3535d05f
...
...
@@ -352,6 +352,13 @@ u.convertUrlToHyperlink = function (url) {
return
url
;
};
u
.
filterQueryParamsFromURL
=
function
(
url
)
{
const
paramsArray
=
api
.
settings
.
get
(
"
filter_url_query_params
"
);
if
(
!
paramsArray
)
return
url
;
const
parsed_uri
=
getURI
(
url
);
return
parsed_uri
.
removeQuery
(
paramsArray
).
toString
();
};
u
.
addHyperlinks
=
function
(
text
)
{
const
objs
=
[];
const
parse_options
=
{
'
start
'
:
/
\
b
(?:([
a
-
z
][
a
-
z0
-
9
.
+-
]
*
:
\
/
\
/
)
|
xmpp
:
|
mailto
:
|
www
\
.)
/
gi
};
...
...
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