Skip to content

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

@jordanpwood

Description

@jordanpwood

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions