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

fixed namespace cleanup when filename contains namespace (e.g. _cq_, … #273

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
JCRRootPrefix = "<jcr:root"
PropPattern = "^\\s*([^ =]+)=\"([^\"]+)\"(.*)$"
NamespacePattern = "^\\w+:(\\w+)=\"[^\"]+\"$"
NamespaceFilePattern = "[\\\\/]_([a-zA-Z0-9]+)_[^\\\\/]+([\\\\/]\\.content)?\\.xml$"
ParentsBackupSuffix = ".bak"
ParentsBackupDirIndicator = ".bakdir"
JCRContentNode = "jcr:content"
Expand All @@ -33,13 +34,15 @@ const (
)

var (
propPatternRegex *regexp.Regexp
namespacePatternRegex *regexp.Regexp
propPatternRegex *regexp.Regexp
namespacePatternRegex *regexp.Regexp
namespaceFilePatternRegex *regexp.Regexp
)

func init() {
propPatternRegex = regexp.MustCompile(PropPattern)
namespacePatternRegex = regexp.MustCompile(NamespacePattern)
namespaceFilePatternRegex = regexp.MustCompile(NamespaceFilePattern)
}

type Manager struct {
Expand Down Expand Up @@ -187,25 +190,31 @@ func (c Manager) filterLines(path string, lines []string) []string {
result = result[:len(result)-1]
}
}
return c.cleanNamespaces(result)
return c.cleanNamespaces(path, result)
}

func (c Manager) cleanNamespaces(lines []string) []string {
func (c Manager) cleanNamespaces(path string, lines []string) []string {
if !c.NamespacesSkipped {
return lines
}

var fileNamespace string
groups := namespaceFilePatternRegex.FindStringSubmatch(path)
if groups != nil {
fileNamespace = groups[1]
}

var result []string
for _, line := range lines {
if strings.HasPrefix(line, JCRRootPrefix) {
var rootResult []string
for _, part := range strings.Split(line, " ") {
groups := namespacePatternRegex.FindStringSubmatch(part)
groups = namespacePatternRegex.FindStringSubmatch(part)
if groups == nil {
rootResult = append(rootResult, part)
} else {
flag := lo.SomeBy(lines, func(line string) bool {
return strings.Contains(line, groups[1]+":")
return strings.Contains(line, groups[1]+":") || groups[1] == fileNamespace
})
if flag {
rootResult = append(rootResult, part)
Expand Down
Loading