Skip to content

Commit da844d1

Browse files
committed
Fix missing Text type for types in need for JSON escaping
1 parent 5a4241c commit da844d1

7 files changed

Lines changed: 84 additions & 5 deletions

File tree

NpgsqlRest/MiddlewareExtension.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ await options.ValidateParametersAsync(new ParameterValidationValues(
767767
object value = reader.GetValue(i);
768768
// AllResultTypesAreUnknown = true always returns string, except for null
769769
string raw = value == DBNull.Value ? "" : (string)value;
770+
770771
if (routine.ReturnsUnnamedSet == false)
771772
{
772773
if (i == 0)

NpgsqlRest/NpgsqlRest.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2929
<PackageReadmeFile>README.MD</PackageReadmeFile>
3030
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
31-
<Version>2.4.0</Version>
32-
<AssemblyVersion>2.4.0</AssemblyVersion>
33-
<FileVersion>2.4.0</FileVersion>
34-
<PackageVersion>2.4.0</PackageVersion>
31+
<Version>2.4.1</Version>
32+
<AssemblyVersion>2.4.1</AssemblyVersion>
33+
<FileVersion>2.4.1</FileVersion>
34+
<PackageVersion>2.4.1</PackageVersion>
3535
</PropertyGroup>
3636

3737
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">

NpgsqlRest/TypeDescriptor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public TypeDescriptor(string type, bool hasDefault = false, bool isPk = false, b
7575
BaseDbType == NpgsqlDbType.JsonPath;
7676

7777
NeedsEscape = BaseDbType == NpgsqlDbType.Xml ||
78+
BaseDbType == NpgsqlDbType.Text ||
7879
BaseDbType == NpgsqlDbType.Varchar ||
7980
BaseDbType == NpgsqlDbType.Char ||
8081
BaseDbType == NpgsqlDbType.Name ||

NpgsqlRestTestWebApi/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ void BuildAuthentication()
209209
auth.AddCookie(cookieScheme, options =>
210210
{
211211
options.ExpireTimeSpan = TimeSpan.FromDays(days);
212+
var name = GetConfigStr("CookieName", authCfg);
213+
if (string.IsNullOrEmpty(name) is false)
214+
{
215+
options.Cookie.Name = GetConfigStr("CookieName", authCfg);
216+
}
217+
options.Cookie.Path = GetConfigStr("CookiePath", authCfg);
218+
options.Cookie.Domain = GetConfigStr("CookieDomain", authCfg);
219+
options.Cookie.MaxAge = GetConfigBool("CookieMultiSessions", authCfg) is true ? TimeSpan.FromDays(days) : null;
220+
options.Cookie.HttpOnly = GetConfigBool("CookieHttpOnly", authCfg) is true;
212221
});
213222
logger?.Information("Using Cookie Authentication with scheme {0}. Cookie expires in {1} days.", cookieScheme, days);
214223
}

NpgsqlRestTestWebApi/appsettings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
"Auth": {
1111
"CookieAuth": true,
1212
"CookieAuthScheme": null,
13-
"CookieExpireDays": 30,
13+
"CookieValidDays": 30,
14+
"CookieName": null,
15+
"CookiePath": null,
16+
"CookieDomain": null,
17+
"CookieMultiSessions": true,
18+
"CookieHttpOnly": true,
1419

1520
"BearerTokenAuth": true,
1621
"BearerTokenAuthScheme": null,

NpgsqlRestTests/QuotedJsonTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
namespace NpgsqlRestTests;
2+
3+
public static partial class Database
4+
{
5+
public static void QuotedJsonTests()
6+
{
7+
script.Append(
8+
"""
9+
create function case_quoted_texts()
10+
returns setof text
11+
language sql
12+
as
13+
$$
14+
select * from (values ('aaa'), ('a''a'), ('a"a'), ('a""a')) sub (a)
15+
$$;
16+
17+
create function case_quoted_text_table()
18+
returns table(t text)
19+
language sql
20+
as
21+
$$
22+
select * from (values
23+
('aaa'),
24+
('a''a'),
25+
('a"a'),
26+
('a""a')
27+
) sub (a)
28+
$$;
29+
""");
30+
}
31+
}
32+
33+
[Collection("TestFixture")]
34+
public class QuotedJsonTests(TestFixture test)
35+
{
36+
[Fact]
37+
public async Task Test_case_quoted_texts()
38+
{
39+
using var result = await test.Client.PostAsync("/api/case-quoted-texts/", null);
40+
var response = await result.Content.ReadAsStringAsync();
41+
42+
result?.StatusCode.Should().Be(HttpStatusCode.OK);
43+
result?.Content?.Headers?.ContentType?.MediaType.Should().Be("application/json");
44+
response.Should().Be("[\"aaa\",\"a'a\",\"a\\\"a\",\"a\\\"\\\"a\"]");
45+
}
46+
47+
[Fact]
48+
public async Task Test_case_quoted_text_table()
49+
{
50+
using var result = await test.Client.PostAsync("/api/case-quoted-text-table/", null);
51+
var response = await result.Content.ReadAsStringAsync();
52+
53+
result?.StatusCode.Should().Be(HttpStatusCode.OK);
54+
result?.Content?.Headers?.ContentType?.MediaType.Should().Be("application/json");
55+
response.Should().Be("[{\"t\":\"aaa\"},{\"t\":\"a'a\"},{\"t\":\"a\\\"a\"},{\"t\":\"a\\\"\\\"a\"}]");
56+
}
57+
}

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Version [2.4.1](https://github.com/vb-consulting/NpgsqlRest/tree/2.4.0) (2024-04-12)
4+
5+
[Full Changelog](https://github.com/vb-consulting/NpgsqlRest/compare/2.4.0...2.4.1)
6+
7+
- Fix missing Text type for types in need for JSON escaping.
8+
39
## Version [2.4.0](https://github.com/vb-consulting/NpgsqlRest/tree/2.4.0) (2024-04-08)
410

511
[Full Changelog](https://github.com/vb-consulting/NpgsqlRest/compare/2.3.1...2.4.0)

0 commit comments

Comments
 (0)