siesta icon indicating copy to clipboard operation
siesta copied to clipboard

Wildcard in PipelineStage.add(_, contentTypes:) doesn't work as expected

Open jordanpwood opened this issue 6 years ago • 0 comments

I am trying add a content transformer to the parsing phase of the Siesta pipeline using the following:

self.service.configure("**") { [weak self] in // all endpoints
        guard let strongSelf = self else {
            return
        }
        
        $0.pipeline[.parsing].add(TextResponseTransformer(), contentTypes: ["*​/xml"])

        /*  other configuration code */
}

However, when a network response with the content type application/xml; charset=utf-8 comes in, the content type is not matching to the regex that Siesta has generated in the add call. I have written the following playground code, which I believe replicates what Siesta is doing when it looks for a matching content type:

import UIKit

var str = "application/xml; charset=utf-8"

let regex = try! NSRegularExpression(pattern: "^[^/+]+\\/xml($|;)")
print(regex.description)
let fullRange = NSRange(location: 0, length: (str as NSString).length)

let match = regex.firstMatch(in: str, options: [], range: fullRange)

As far as I can tell, this should replicate what Siesta does in the file Regex+Siesta.swiftin its extension NSRegularExpression.matches(). However, the above playground code gets a match while Siesta does not. If I change the pipeline transformer add to:

$0.pipeline[.parsing].add(TextResponseTransformer(), contentTypes: ["application/xml"])

It works as expected. Why won't the pattern */xml work? It seems like it should.

Thanks for the help with this!

jordanpwood avatar Mar 18 '19 14:03 jordanpwood