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
22113a8c
Commit
22113a8c
authored
Jul 16, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand test for rendering of images (and fix accordingly)
parent
12510a96
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
17 deletions
+38
-17
spec/chatbox.js
spec/chatbox.js
+19
-9
src/utils.js
src/utils.js
+19
-8
No files found.
spec/chatbox.js
View file @
22113a8c
...
...
@@ -1321,12 +1321,6 @@
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
if
(
/PhantomJS/
.
test
(
window
.
navigator
.
userAgent
))
{
// Doesn't work when running tests in PhantomJS, since
// the page is loaded via file:///
done
();
return
;
}
test_utils
.
createContacts
(
_converse
,
'
current
'
);
var
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
var
message
=
base_url
+
"
/logo/conversejs.svg
"
;
...
...
@@ -1356,6 +1350,22 @@
'
<a target="_blank" rel="noopener" href="
'
+
base_url
+
'
/logo/conversejs.svg?param1=val1&param2=val2"><img src="
'
+
message
.
replace
(
/&/g
,
'
&
'
)
+
'
" class="chat-image"></a>
'
)
// Test now with two images in one message
message
+=
'
hello world
'
+
base_url
+
"
/logo/conversejs.svg
"
;
test_utils
.
sendMessage
(
view
,
message
);
return
test_utils
.
waitUntil
(
function
()
{
return
view
.
$el
.
find
(
'
.chat-content
'
).
find
(
'
.chat-message img
'
).
length
===
4
;
},
500
);
}).
then
(
function
()
{
expect
(
view
.
sendMessage
).
toHaveBeenCalled
();
var
msg
=
view
.
$el
.
find
(
'
.chat-content
'
).
find
(
'
.chat-message
'
).
last
().
find
(
'
.chat-msg-content
'
);
expect
(
msg
.
html
()).
toEqual
(
'
<a target="_blank" rel="noopener" href="
'
+
base_url
+
'
/logo/conversejs.svg?param1=val1&param2=val2">
'
+
'
<img src="
'
+
base_url
+
'
/logo/conversejs.svg?param1=val1&param2=val2" class="chat-image"></a> hello world
'
+
'
<a target="_blank" rel="noopener" href="
'
+
base_url
+
'
/logo/conversejs.svg">
'
+
'
<img src="
'
+
base_url
+
'
/logo/conversejs.svg" class="chat-image"></a>
'
)
done
();
});
}));
...
...
src/utils.js
View file @
22113a8c
...
...
@@ -36,8 +36,11 @@
)
{
"
use strict
"
;
locales
=
locales
||
{};
const
b64_sha1
=
Strophe
.
SHA1
.
b64_sha1
;
Strophe
=
Strophe
.
Strophe
;
const
URL_REGEX
=
/
\b(
https
?
:
\/\/
|www
\.
|https
?
:
\/\/
www
\.)[^\s
<>
]{2,200}\b
/g
;
var
XFORM_TYPE_MAP
=
{
'
text-private
'
:
'
password
'
,
'
text-single
'
:
'
text
'
,
...
...
@@ -154,24 +157,32 @@
};
utils
.
addHyperlinks
=
function
(
text
)
{
var
list
=
text
.
match
(
/
\b(
https
?
:
\/\/
|www
\.
|https
?
:
\/\/
www
\.)[^\s
<>
]{2,200}\b
/g
)
||
[];
const
list
=
text
.
match
(
URL_REGEX
)
||
[];
var
links
=
[];
_
.
each
(
list
,
(
match
)
=>
{
const
prot
=
match
.
indexOf
(
'
http://
'
)
===
0
||
match
.
indexOf
(
'
https://
'
)
===
0
?
''
:
'
http://
'
;
const
url
=
prot
+
encodeURI
(
decodeURI
(
match
)).
replace
(
/
[
!'()
]
/g
,
escape
).
replace
(
/
\*
/g
,
"
%2A
"
);
text
=
text
.
replace
(
match
,
'
<a target="_blank" rel="noopener" href="
'
+
url
+
'
">
'
+
match
+
'
</a>
'
);
const
a
=
'
<a target="_blank" rel="noopener" href="
'
+
url
+
'
">
'
+
_
.
escape
(
match
)
+
'
</a>
'
;
// We first insert a hash of the code that will be inserted, and
// then later replace that with the code itself. That way we avoid
// issues when some matches are substrings of others.
links
.
push
(
a
);
text
=
text
.
replace
(
match
,
b64_sha1
(
a
));
});
while
(
links
.
length
)
{
const
a
=
links
.
pop
();
text
=
text
.
replace
(
b64_sha1
(
a
),
a
);
}
return
text
;
};
utils
.
renderImageURLs
=
function
(
obj
)
{
var
list
=
obj
.
textContent
.
match
(
/
\b(
https
?
:
\/\/
|www
\.
|https
?
:
\/\/
www
\.)[^\s
<>
]{2,200}\b
/g
)
||
[];
const
list
=
obj
.
textContent
.
match
(
URL_REGEX
)
||
[];
_
.
forEach
(
list
,
function
(
url
)
{
isImage
(
u
nescapeHTML
(
url
)
).
then
(
function
(
img
)
{
isImage
(
u
rl
).
then
(
function
(
img
)
{
img
.
className
=
'
chat-image
'
;
var
a
=
obj
.
querySelector
(
'
a
'
);
if
(
!
_
.
isNull
(
a
))
{
a
.
innerHTML
=
img
.
outerHTML
;
}
var
anchors
=
sizzle
(
`a[href="
${
url
}
"]`
,
obj
);
_
.
each
(
anchors
,
(
a
)
=>
{
a
.
innerHTML
=
img
.
outerHTML
;
});
});
});
return
obj
;
...
...
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