Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DNS servers with same tag wrongly merged #3005

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Vigilans
Copy link
Contributor

@Vigilans Vigilans commented May 7, 2024

Fixes #2981

Comment on lines +27 to +35
func mergeSameTag(s []interface{}, path string) ([]interface{}, error) {
// from: [a,"",b,"",a,"",b,""]
// to: [a,"",b,"",merged,"",merged,""]
merged := &struct{}{}
tagKeyOnly := false
// See https://github.com/v2fly/v2ray-core/issues/2981
if strings.HasPrefix(path, ".dns.servers") {
tagKeyOnly = true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For certain settings (identified by path), do not use "tag" field to search for tag. "_tag" is preserved.

// from: [a,"",b,"",a,"",b,""]
// to: [a,"",b,"",merged,"",merged,""]
merged := &struct{}{}
tagKeyOnly := false
// See https://github.com/v2fly/v2ray-core/issues/2981
if strings.HasPrefix(path, ".dns.servers") {
Copy link

@povsister povsister May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to documentation, mergeSameTag should only be applied on inbounds and outbounds.
This looks like a "workaround" instead of a real fix for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to apply it to only inbounds and outbounds, but it will actually break this test that also applies to routing config:

func TestMergeTag(t *testing.T) {
json1 := `
{
"routing": {
"rules": [{
"tag":"1",
"inboundTag": ["in-1"],
"outboundTag": "out-1"
}]
}
}
`
json2 := `
{
"routing": {
"rules": [{
"_tag":"1",
"inboundTag": ["in-2"],
"outboundTag": "out-2"
}]
}
}
`
expected := `
{
"routing": {
"rules": [{
"tag":"1",
"inboundTag": ["in-1", "in-2"],
"outboundTag": "out-2"
}]
}
}
`
m, err := merge.JSONs([][]byte{[]byte(json1), []byte(json2)})
if err != nil {
t.Error(err)
}
assertResult(t, m, expected)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DNS servers with same tag in a SINGLE configuration file got unexpected merged
2 participants