mirror of
https://github.com/v2fly/domain-list-community.git
synced 2024-11-16 17:14:52 +02:00
support recursive inclusion
This commit is contained in:
parent
eb9152dbe4
commit
1dc2cd7e04
37
main.go
37
main.go
@ -119,22 +119,33 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
|||||||
Name: list.Name,
|
Name: list.Name,
|
||||||
Inclusion: make(map[string]bool),
|
Inclusion: make(map[string]bool),
|
||||||
}
|
}
|
||||||
for _, entry := range list.Entry {
|
entryList := list.Entry
|
||||||
if entry.Type == "include" {
|
for {
|
||||||
if pl.Inclusion[entry.Value] {
|
newEntryList := make([]Entry, 0, len(entryList))
|
||||||
continue
|
hasInclude := false
|
||||||
|
for _, entry := range entryList {
|
||||||
|
if entry.Type == "include" {
|
||||||
|
if pl.Inclusion[entry.Value] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
refName := strings.ToUpper(entry.Value)
|
||||||
|
pl.Inclusion[refName] = true
|
||||||
|
r := ref[refName]
|
||||||
|
if r == nil {
|
||||||
|
return nil, errors.New(entry.Value + " not found.")
|
||||||
|
}
|
||||||
|
newEntryList = append(newEntryList, r.Entry...)
|
||||||
|
hasInclude = true
|
||||||
|
} else {
|
||||||
|
newEntryList = append(newEntryList, entry)
|
||||||
}
|
}
|
||||||
refName := strings.ToUpper(entry.Value)
|
}
|
||||||
pl.Inclusion[refName] = true
|
entryList = newEntryList
|
||||||
r := ref[refName]
|
if !hasInclude {
|
||||||
if r == nil {
|
break
|
||||||
return nil, errors.New(entry.Value + " not found.")
|
|
||||||
}
|
|
||||||
pl.Entry = append(pl.Entry, r.Entry...)
|
|
||||||
} else {
|
|
||||||
pl.Entry = append(pl.Entry, entry)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pl.Entry = entryList
|
||||||
|
|
||||||
return pl, nil
|
return pl, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user