@subiz/widget-v4 4.1.151 → 4.1.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -180,7 +180,7 @@ class Block extends _common.Com {
|
|
|
180
180
|
case 'a':
|
|
181
181
|
return (0, _preact.h)("a", {
|
|
182
182
|
href: ele.attrs['href'],
|
|
183
|
-
target: ele.attrs['target'],
|
|
183
|
+
target: this.props.textMessage ? '_blank' : ele.attrs['target'],
|
|
184
184
|
title: ele.attrs['title']
|
|
185
185
|
}, $body);
|
|
186
186
|
case 'Emoji':
|
|
@@ -141,7 +141,7 @@ function extractEmojis(text) {
|
|
|
141
141
|
}
|
|
142
142
|
function extractLinks(text) {
|
|
143
143
|
text = text || '';
|
|
144
|
-
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-
|
|
144
|
+
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{2,6}\b([-a-zA-Z0-9@:%_\+.,~#?&//=]*)/gim;
|
|
145
145
|
var out = [];
|
|
146
146
|
var match;
|
|
147
147
|
while (match = reg.exec(text)) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function extractLinks(text) {
|
|
4
|
+
text = text || '';
|
|
5
|
+
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{2,6}\b([-a-zA-Z0-9@:%_\+.,~#?&//=]*)/gim;
|
|
6
|
+
var out = [];
|
|
7
|
+
var match;
|
|
8
|
+
while (match = reg.exec(text)) {
|
|
9
|
+
out.push({
|
|
10
|
+
index: match.index,
|
|
11
|
+
length: reg.lastIndex - match.index
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
function main() {
|
|
17
|
+
var tcs = [{
|
|
18
|
+
text: '',
|
|
19
|
+
out: []
|
|
20
|
+
}, {
|
|
21
|
+
text: 'vao https://subiz.com a',
|
|
22
|
+
out: [{
|
|
23
|
+
index: 4,
|
|
24
|
+
length: 17
|
|
25
|
+
}]
|
|
26
|
+
}, {
|
|
27
|
+
text: 'day htt://a.com',
|
|
28
|
+
out: [{
|
|
29
|
+
index: 10,
|
|
30
|
+
length: 5
|
|
31
|
+
}]
|
|
32
|
+
}, {
|
|
33
|
+
text: 'chao http://http.ne/22',
|
|
34
|
+
out: [{
|
|
35
|
+
index: 5,
|
|
36
|
+
length: 17
|
|
37
|
+
}]
|
|
38
|
+
}, {
|
|
39
|
+
text: 'chao google.com',
|
|
40
|
+
out: [{
|
|
41
|
+
index: 5,
|
|
42
|
+
length: 10
|
|
43
|
+
}]
|
|
44
|
+
}, {
|
|
45
|
+
text: 'Bạn có thể xem hình ảnh của Mazda2 1.5L AT qua liên kết dưới đây:',
|
|
46
|
+
out: []
|
|
47
|
+
}, {
|
|
48
|
+
text: 'Giá: 386.000.000 VNĐ',
|
|
49
|
+
out: []
|
|
50
|
+
}];
|
|
51
|
+
for (var i = 0; i < tcs.length; i++) {
|
|
52
|
+
var tc = tcs[i];
|
|
53
|
+
var out = extractLinks(tc.text);
|
|
54
|
+
if (JSON.stringify(out) !== JSON.stringify(tc.out)) {
|
|
55
|
+
console.error('FAIL', tc.text, '\n', JSON.stringify(out, null, 4), '\n', JSON.stringify(tc.out, null, 4));
|
|
56
|
+
} else {
|
|
57
|
+
console.info('PASS', tc.text);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
main();
|
package/package.json
CHANGED
package/src/chatbox/block.js
CHANGED
|
@@ -187,7 +187,11 @@ export default class Block extends Com {
|
|
|
187
187
|
return <hr />
|
|
188
188
|
case 'a':
|
|
189
189
|
return (
|
|
190
|
-
<a
|
|
190
|
+
<a
|
|
191
|
+
href={ele.attrs['href']}
|
|
192
|
+
target={this.props.textMessage ? '_blank' : ele.attrs['target']}
|
|
193
|
+
title={ele.attrs['title']}
|
|
194
|
+
>
|
|
191
195
|
{$body}
|
|
192
196
|
</a>
|
|
193
197
|
)
|
package/src/util/common.js
CHANGED
|
@@ -97,7 +97,7 @@ export function extractEmojis(text) {
|
|
|
97
97
|
|
|
98
98
|
export function extractLinks(text) {
|
|
99
99
|
text = text || ''
|
|
100
|
-
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-
|
|
100
|
+
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{2,6}\b([-a-zA-Z0-9@:%_\+.,~#?&//=]*)/gim
|
|
101
101
|
var out = []
|
|
102
102
|
var match
|
|
103
103
|
while ((match = reg.exec(text))) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// somehow require error so we need copy paste function test here
|
|
2
|
+
function extractLinks(text) {
|
|
3
|
+
text = text || ''
|
|
4
|
+
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{2,6}\b([-a-zA-Z0-9@:%_\+.,~#?&//=]*)/gim
|
|
5
|
+
var out = []
|
|
6
|
+
var match
|
|
7
|
+
while ((match = reg.exec(text))) {
|
|
8
|
+
out.push({index: match.index, length: reg.lastIndex - match.index})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return out
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function main() {
|
|
15
|
+
var tcs = [
|
|
16
|
+
{
|
|
17
|
+
text: '',
|
|
18
|
+
out: [],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
text: 'vao https://subiz.com a',
|
|
22
|
+
out: [{ index: 4, length: 17 }],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
text: 'day htt://a.com',
|
|
26
|
+
out: [{ index: 10, length: 5 }],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
text: 'chao http://http.ne/22',
|
|
30
|
+
out: [{ index: 5, length: 17 }],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
text: 'chao google.com',
|
|
34
|
+
out: [{ index: 5, length: 10 }],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
text: 'Bạn có thể xem hình ảnh của Mazda2 1.5L AT qua liên kết dưới đây:',
|
|
38
|
+
out: [],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
text: 'Giá: 386.000.000 VNĐ',
|
|
42
|
+
out: [],
|
|
43
|
+
},
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
for (var i = 0; i < tcs.length; i++) {
|
|
47
|
+
var tc = tcs[i]
|
|
48
|
+
var out = extractLinks(tc.text)
|
|
49
|
+
if (JSON.stringify(out) !== JSON.stringify(tc.out)) {
|
|
50
|
+
console.error('FAIL', tc.text, '\n', JSON.stringify(out, null, 4), '\n', JSON.stringify(tc.out, null, 4))
|
|
51
|
+
} else {
|
|
52
|
+
console.info('PASS', tc.text)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
main()
|