fix orphans
This commit is contained in:
@@ -39,9 +39,19 @@ func InjectColor(r *http.Request, ctx context.Context, handler http.Handler, w h
|
||||
body := buf.Bytes()
|
||||
|
||||
// this models after the Radicale Response, largely AI code
|
||||
// 1. Add namespaces to the root multistatus tag
|
||||
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
||||
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:ICAL="http://apple.com/ns/ical/" xmlns:C="urn:ietf:params:xml:ns:caldav" xmlns:CS="http://calendarserver.org/ns/"`))
|
||||
// 1. Add namespaces to the root multistatus tag only if they are missing
|
||||
if !bytes.Contains(body, []byte("xmlns:ICAL=")) {
|
||||
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
||||
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:ICAL="http://apple.com/ns/ical/"`))
|
||||
}
|
||||
if !bytes.Contains(body, []byte("xmlns:C=")) && !bytes.Contains(body, []byte("xmlns:c=")) {
|
||||
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
||||
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:C="urn:ietf:params:xml:ns:caldav"`))
|
||||
}
|
||||
if !bytes.Contains(body, []byte("xmlns:CS=")) {
|
||||
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
||||
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:CS="http://calendarserver.org/ns/"`))
|
||||
}
|
||||
|
||||
// 2. Response processing
|
||||
reResponse := regexp.MustCompile(`(?s)<[a-zA-Z0-9]*:?response.*?>.*?</[a-zA-Z0-9]*:?response>`)
|
||||
@@ -62,7 +72,7 @@ func InjectColor(r *http.Request, ctx context.Context, handler http.Handler, w h
|
||||
return resp
|
||||
}
|
||||
|
||||
// 1. Strip any existing conflicting tags that might be in 404 blocks
|
||||
// 1. Strip any existing conflicting tags that might be in 404 blocks (non-greedy)
|
||||
reStrip := regexp.MustCompile(`(?s)<[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order).*?/>|<[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order).*?>.*?</[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order)>`)
|
||||
resp = reStrip.ReplaceAll(resp, []byte(""))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user