Setting response headers with custom variables isn't working

If I do this:

response:
    Access-Control-Allow-Origin: "'https://www.example.com'"

The header value is set correctly with single quotes in CloudFormation as

'https://www.example.com'

If I do this:

 custom:
    dev:
      ACCESS_CONTROL_ALLOW_ORIGIN: "'https://www.example.com'"
response:
     Access-Control-Allow-Origin: ${self:custom.${opt:stage}.ACCESS_CONTROL_ALLOW_ORIGIN}

The header value is incorrectly set with two single quotes as

''https://www.example.com''

This breaks my application. I’ve tried everything and I either get the incorrect output shown above or deployment will fail due to malformed header.

Is it not possible to dynamically set response headers with custom variables?

Turns out I was on a very old version of Serverless (1.4x). Upgrading to 1.7x fixed this.