diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dd289677..e846d5715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #1180, Fix embedding on views with subselects in pg10 - @steve-chavez - #1197, Allow CORS for PUT - @bkylerussell - #1181, Correctly qualify function argument of custom type in public schema - @steve-chavez +- #1008, Allow columns that contain spaces in filters - @steve-chavez ## [5.1.0] - 2018-08-31 diff --git a/src/PostgREST/Parsers.hs b/src/PostgREST/Parsers.hs index 97a12b2e4..85a2a6931 100644 --- a/src/PostgREST/Parsers.hs +++ b/src/PostgREST/Parsers.hs @@ -74,7 +74,7 @@ pStar = toS <$> (string "*" $> ("*"::ByteString)) pFieldName :: Parser Text pFieldName = intercalate "-" . map toS <$> - (many1 (letter <|> digit <|> oneOf "_") `sepBy1` dash) + (many1 (letter <|> digit <|> oneOf "_ ") `sepBy1` dash) "field name (* or [a..z0..9_])" where isDash :: GenParser Char st () diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 95621430e..058b15282 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -819,6 +819,15 @@ spec = do [json| [{"escapeId":{"so6meIdColumn":1}},{"escapeId":{"so6meIdColumn":3}},{"escapeId":{"so6meIdColumn":5}}] |] { matchHeaders = [matchContentTypeJson] } + it "will select and filter a column that has spaces" $ + get "/Server%20Today?select=Just%20A%20Server%20Model&Just%20A%20Server%20Model=like.*91*" `shouldRespondWith` + [json|[ + {"Just A Server Model":" IBM,9113-550 (P5-550)"}, + {"Just A Server Model":" IBM,9113-550 (P5-550)"}, + {"Just A Server Model":" IBM,9131-52A (P5-52A)"}, + {"Just A Server Model":" IBM,9133-55A (P5-55A)"}]|] + { matchHeaders = [matchContentTypeJson] } + describe "binary output" $ do context "on GET" $ do it "can query if a single column is selected" $ diff --git a/test/fixtures/data.sql b/test/fixtures/data.sql index a1f7fe800..1f7b7a815 100644 --- a/test/fixtures/data.sql +++ b/test/fixtures/data.sql @@ -473,3 +473,12 @@ INSERT INTO ltree_sample VALUES ('Top.Science.Astronomy.Cosmology'); TRUNCATE TABLE isn_sample CASCADE; INSERT INTO isn_sample VALUES ('978-0-393-04002-9', 'Mathematics: From the Birth of Numbers'); + +TRUNCATE TABLE "Server Today" CASCADE; +COPY "Server Today" ("cHostname", "Just A Server Model") FROM STDIN CSV DELIMITER '|'; +argnim1 | IBM,9113-550 (P5-550) +argnim2 | IBM,9113-550 (P5-550) +daaa2nim71 | IBM,9131-52A (P5-52A) +daah3nim71 | IBM,8406-71Y (P7-PS701) +hbnim1 | IBM,9133-55A (P5-55A) +\. diff --git a/test/fixtures/privileges.sql b/test/fixtures/privileges.sql index d86689348..fd9203a42 100644 --- a/test/fixtures/privileges.sql +++ b/test/fixtures/privileges.sql @@ -96,6 +96,7 @@ GRANT ALL ON TABLE , ltree_sample , isn_sample , projects_count_grouped_by + , "Server Today" TO postgrest_test_anonymous; GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous; diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index 2d298c713..8e888d16f 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -1636,3 +1636,8 @@ create table test.isn_sample ( create function test.is_valid_isbn(input text) returns boolean as $$ select is_valid(input::isbn); $$ language sql; + +create table "Server Today"( + "cHostname" text, + "Just A Server Model" text +);