Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
fcc32acd
Commit
fcc32acd
authored
Mar 08, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ui/scripts/Utils/utils.js): `encodeTextToQmlRichFormat` parse correctly urls
parent
8c990b06
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
32 deletions
+135
-32
uri-tools.js
linphone-desktop/ui/scripts/Utils/uri-tools.js
+3
-3
utils.js
linphone-desktop/ui/scripts/Utils/utils.js
+67
-28
utils.spec.qml
linphone-desktop/ui/scripts/Utils/utils.spec.qml
+65
-1
No files found.
linphone-desktop/ui/scripts/Utils/uri-tools.js
View file @
fcc32acd
...
...
@@ -20,8 +20,8 @@ var URI_UNRESERVED = '[\\w\-\._~]'
// Level 1. --------------------------------------------------------------------
var
URI_HOST
=
'
(
'
+
'
(
'
+
var
URI_HOST
=
'
(
?:
'
+
'
(
?:
'
+
URI_UNRESERVED
+
'
|
'
+
URI_PCT_ENCODED
+
'
|
'
+
URI_SUB_DELIMS
+
...
...
@@ -90,7 +90,7 @@ var URI = (SUPPORTS_URL
)
+
URI_HIER_PART
+
'
(?:
'
+
'
\\
?
'
+
URI_QUERY
+
'
)?
'
+
'
(?:
'
+
'
#
'
+
URI_FRAGMENT
+
'
)?
'
var
URI_REGEX
=
new
RegExp
(
URI
,
'
g
'
)
var
URI_REGEX
=
new
RegExp
(
'
(
'
+
URI
+
'
)
'
,
'
g
'
)
// =============================================================================
...
...
linphone-desktop/ui/scripts/Utils/utils.js
View file @
fcc32acd
...
...
@@ -48,40 +48,35 @@ function encodeTextToQmlRichFormat (text, options) {
options
=
{}
}
text
=
text
.
replace
(
/&/g
,
'
&
'
)
// TODO: deal correctly with urls and `&m`
.
replace
(
/</g
,
'
\
u2063<
'
)
.
replace
(
/>/g
,
'
\
u2063>
'
)
.
replace
(
/
\r\n
|
\n
/g
,
'
<br/>
'
)
.
replace
(
/
\t
/g
,
'
'
)
.
replace
(
/ /g
,
'
'
)
.
replace
(
UriTools
.
URI_REGEX
,
function
(
match
)
{
// If it's a simple URL, transforms it in URI.
if
(
startsWith
(
match
,
'
www.
'
))
{
match
=
'
http://
'
+
match
}
var
ext
=
getExtension
(
match
)
if
(
includes
([
'
jpg
'
,
'
jpeg
'
,
'
gif
'
,
'
png
'
,
'
svg
'
],
ext
))
{
images
+=
'
<a href="
'
+
match
+
'
"><img
'
+
(
options
.
imagesWidth
!=
null
?
'
width="
'
+
options
.
imagesWidth
+
'
"
'
:
''
)
+
(
options
.
imagesHeight
!=
null
?
'
height="
'
+
options
.
imagesHeight
+
'
"
'
:
''
)
+
'
src="
'
+
match
+
'
" /></a>
'
}
var
formattedText
=
execAll
(
UriTools
.
URI_REGEX
,
text
,
function
(
str
,
valid
)
{
if
(
!
valid
)
{
return
unscapeHtml
(
str
).
replace
(
/
\r\n
|
\n
/g
,
'
<br/>
'
)
.
replace
(
/
\t
/g
,
'
'
)
.
replace
(
/ /g
,
'
'
)
}
return
'
<a href="
'
+
match
+
'
">
'
+
match
+
'
</a>
'
})
var
uri
=
startsWith
(
str
,
'
www.
'
)
?
'
http://
'
+
str
:
str
var
ext
=
getExtension
(
str
)
if
(
includes
([
'
jpg
'
,
'
jpeg
'
,
'
gif
'
,
'
png
'
,
'
svg
'
],
ext
))
{
images
+=
'
<a href="
'
+
uri
+
'
"><img
'
+
(
options
.
imagesWidth
!=
null
?
'
width="
'
+
options
.
imagesWidth
+
'
"
'
:
''
)
+
(
options
.
imagesHeight
!=
null
?
'
height="
'
+
options
.
imagesHeight
+
'
"
'
:
''
)
+
'
src="
'
+
str
+
'
" /></a>
'
}
return
'
<a href="
'
+
uri
+
'
">
'
+
str
+
'
</a>
'
}).
join
(
''
)
if
(
images
.
length
>
0
)
{
images
=
'
<div>
'
+
images
+
'
</div>
'
}
return
images
.
concat
(
'
<p>
'
+
t
ext
+
'
</p>
'
)
return
images
.
concat
(
'
<p>
'
+
formattedT
ext
+
'
</p>
'
)
}
function
extractFirstUri
(
str
)
{
...
...
@@ -301,6 +296,40 @@ function dirname (str) {
// -----------------------------------------------------------------------------
function
execAll
(
regex
,
text
,
cb
)
{
var
index
=
0
var
arr
=
[]
var
match
if
(
!
cb
)
{
cb
=
function
(
text
)
{
return
text
}
}
while
((
match
=
regex
.
exec
(
text
)))
{
var
curIndex
=
match
.
index
var
matchStr
=
match
[
0
]
if
(
curIndex
>
index
)
{
arr
.
push
(
cb
(
text
.
substring
(
index
,
curIndex
),
false
))
}
arr
.
push
(
cb
(
matchStr
,
true
))
index
=
curIndex
+
matchStr
.
length
}
var
length
=
text
.
length
if
(
index
<
length
)
{
arr
.
push
(
cb
(
text
.
substring
(
index
,
length
)))
}
return
arr
}
// -----------------------------------------------------------------------------
function
extractProperties
(
obj
,
pattern
)
{
if
(
!
pattern
)
{
return
{}
...
...
@@ -560,3 +589,13 @@ function times (n, cb, context) {
return
arr
}
// -----------------------------------------------------------------------------
function
unscapeHtml
(
str
)
{
return
str
.
replace
(
/&/g
,
'
&
'
)
.
replace
(
/</g
,
'
\
u2063<
'
)
.
replace
(
/>/g
,
'
\
u2063>
'
)
.
replace
(
/"/g
,
'
"
'
)
.
replace
(
/'/g
,
'
'
'
)
}
linphone-desktop/ui/scripts/Utils/utils.spec.qml
View file @
fcc32acd
...
...
@@ -145,12 +145,76 @@ TestCase {
function
test_ensureArray
(
data
)
{
// Use `sort` because transform a object in array hasn't a
// guarantee order.
// guarantee order
ing
.
compare
(
Utils
.
ensureArray
(
data
.
input
).
sort
(),
data
.
output
.
sort
())
}
// ---------------------------------------------------------------------------
function
test_execAll_data
()
{
return
[
{
cb
:
function
()
{
return
'
failed
'
},
regex
:
/x/g
,
text
:
''
,
output
:
[]
},
{
cb
:
function
(
c
,
valid
)
{
return
!
valid
&&
c
},
regex
:
/x/g
,
text
:
'
n
'
,
output
:
[
'
n
'
]
},
{
cb
:
function
(
c
,
valid
)
{
return
valid
&&
String
.
fromCharCode
(
c
.
charCodeAt
(
0
)
+
1
)
},
regex
:
/
[
a-z
]
/g
,
text
:
'
abcdefgh
'
,
output
:
[
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
,
'
f
'
,
'
g
'
,
'
h
'
,
'
i
'
]
},
{
cb
:
function
(
n
,
valid
)
{
return
!
valid
?
'
*
'
:
Math
.
abs
(
n
)
},
regex
:
/
\d
+/g
,
text
:
'
abc 5 def -4 ghi 452-12
'
,
output
:
[
'
*
'
,
5
,
'
*
'
,
4
,
'
*
'
,
452
,
'
*
'
,
12
]
},
{
regex
:
/candy-shop/g
,
text
:
'
candy-hop candy-shop cndy-shop candyshop
'
,
output
:
[
'
candy-hop
'
,
'
candy-shop
'
,
'
cndy-shop candyshop
'
]
},
{
cb
:
function
(
text
,
valid
)
{
return
valid
?
text
+
'
Batman!
'
:
text
},
regex
:
/
(?:
na
)
+
\.\.\.
/g
,
text
:
'
Nananana. Nanananananananana... Nanananananananana... Nananananananananananana...
'
,
output
:
[
'
Nananana. Na
'
,
'
nananananananana... Batman!
'
,
'
Na
'
,
'
nananananananana... Batman!
'
,
'
Na
'
,
'
nanananananananananana... Batman!
'
]
}
]
}
function
test_execAll
(
data
)
{
compare
(
Utils
.
execAll
(
data
.
regex
,
data
.
text
,
data
.
cb
),
data
.
output
)
}
// ---------------------------------------------------------------------------
function
test_genRandomNumber_data
()
{
return
[
{
min
:
42
,
max
:
3600
},
...
...
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