From ceb89d7331f10672b46534aafd881ee5861623e3 Mon Sep 17 00:00:00 2001 From: Patrik Ragnarsson Date: Wed, 28 Dec 2022 18:43:11 +0100 Subject: [PATCH] Rack 3 does not allow newlines in headers See https://github.com/rack/rack/issues/1598, https://github.com/rack/rack/pull/1793 --- sinatra-contrib/lib/sinatra/link_header.rb | 8 ++++---- sinatra-contrib/spec/link_header_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sinatra-contrib/lib/sinatra/link_header.rb b/sinatra-contrib/lib/sinatra/link_header.rb index fcf1dcb41e..022c26bbdd 100644 --- a/sinatra-contrib/lib/sinatra/link_header.rb +++ b/sinatra-contrib/lib/sinatra/link_header.rb @@ -89,10 +89,10 @@ def link(*urls) link = (response['Link'] ||= '') urls.map do |url| - link << ",\n" unless link.empty? + link << "," unless link.empty? link << (http_pattern % url) html_pattern % url - end.join "\n" + end.join end ## @@ -117,10 +117,10 @@ def link_headers yield if block_given? return '' unless response.include? 'Link' - response['Link'].split(",\n").map do |line| + response['Link'].split(",").map do |line| url, *opts = line.split(';').map(&:strip) "" - end.join "\n" + end.join end def self.registered(_base) diff --git a/sinatra-contrib/spec/link_header_spec.rb b/sinatra-contrib/spec/link_header_spec.rb index f18cabb0fe..dfd07c8e04 100644 --- a/sinatra-contrib/spec/link_header_spec.rb +++ b/sinatra-contrib/spec/link_header_spec.rb @@ -41,7 +41,7 @@ it "takes an options hash" do get '/' elements = ["", "foo=\"bar\"", "rel=\"from-filter\""] - expect(headers['Link'].split(",\n").first.strip.split('; ').sort).to eq(elements) + expect(headers['Link'].split(",").first.strip.split('; ').sort).to eq(elements) end end