Skip to content

Commit 8e4a574

Browse files
committed
Support the regular expression of port in merge rules (sheepzh#75)
1 parent 8a49684 commit 8e4a574

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/app/components/rule-merge/alert-info.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77

88
import { ElAlert } from "element-plus"
99
import { t } from "@app/locale"
10-
import { h } from "vue"
10+
import { defineComponent, h } from "vue"
1111
import { MergeRuleMessage } from "@app/locale/components/merge-rule"
1212

1313
const liKeys: (keyof MergeRuleMessage)[] = ['infoAlert0', 'infoAlert1', 'infoAlert2', 'infoAlert3', 'infoAlert4', 'infoAlert5']
14+
const title = t(msg => msg.mergeRule.infoAlertTitle)
1415

15-
const alertInfo = () => h(ElAlert,
16-
{ type: 'info', title: t(msg => msg.mergeRule.infoAlertTitle) },
17-
() => liKeys.map(key => h('li', t(msg => msg.mergeRule[key])))
18-
)
16+
const _default = defineComponent({
17+
name: "RuleMergeAlertInfo",
18+
render() {
19+
return h(ElAlert,
20+
{ type: 'info', title },
21+
() => liKeys.map(key => h('li', t(msg => msg.mergeRule[key])))
22+
)
23+
}
24+
})
1925

20-
export default alertInfo
26+
export default _default

src/app/components/rule-merge/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
import '../common/editable-tag'
99
import { defineComponent } from "vue"
1010
import ContentContainer from "../common/content-container"
11-
import alertInfo from "./alert-info"
11+
import RuleMergeAlertInfo from "./alert-info"
1212
import itemList from "./item-list"
1313
import { ElCard } from "element-plus"
1414
import { h } from "vue"
1515

1616
const _default = defineComponent({
1717
name: "RuleMerge",
1818
setup() {
19-
return () => h(ContentContainer, {},
20-
{
21-
default: () => h(ElCard, {}, () => [alertInfo(), itemList()])
22-
})
19+
return () => h(ContentContainer, () => h(ElCard, () => [
20+
h(RuleMergeAlertInfo),
21+
itemList()
22+
]))
2323
}
2424
})
2525

src/util/pattern.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import { IS_CHROME, IS_EDGE } from "./constant/environment"
98
import { SUFFIX_HOST_MAP } from "./constant/remain-host"
109

1110
/**
@@ -54,7 +53,7 @@ export function isValidHost(host: string) {
5453
const indexOfColon = host.indexOf(':')
5554
if (indexOfColon > -1) {
5655
const portStr = host.substring(indexOfColon + 1)
57-
if (isNotValidPort(portStr)) {
56+
if (portStr !== '*' && isNotValidPort(portStr)) {
5857
return false
5958
}
6059
host = host.substring(0, indexOfColon)

test/util/pattern.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ test('ip and port', () => {
2121
expect(isIpAndPort('222.222.22.2:65535')).toBeTruthy()
2222
// 65536 is invalid port
2323
expect(isIpAndPort('222.222.22.2:65536')).toBeFalsy()
24+
// Regular expression is not valid
25+
expect(isIpAndPort('222.222.22.2:*')).toBeFalsy()
2426
})
2527

2628
test('merge host origin', () => {
2729
expect(isValidHost('wwdad.basd.com.111:12345')).toBeTruthy()
2830
expect(isValidHost('wwdad.basd.com.a111a:12345')).toBeTruthy()
31+
expect(isValidHost('wwdad.basd.com.a111a:*')).toBeTruthy()
2932
expect(isValidHost('wwdad.basd.**:12345')).toBeFalsy()
3033
expect(isValidHost('wwdad.basd.**:65536')).toBeFalsy()
3134
expect(isValidHost('wwdad.basd.*.*')).toBeTruthy()

0 commit comments

Comments
 (0)