Skip to content

Commit 38129ec

Browse files
committed
client-v2.15.0 parser fix
1 parent 8d1c3a5 commit 38129ec

File tree

8 files changed

+41
-20
lines changed

8 files changed

+41
-20
lines changed

.github/workflows/build-test-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
env:
4444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4545
with:
46-
tag_name: v2.20.0-client-v2.14.0
47-
release_name: "AOT Client v2.14.0 NpgsqlRest v2.20.0"
46+
tag_name: v2.20.0-client-v2.15.0
47+
release_name: "AOT Client v2.15.0 NpgsqlRest v2.20.0"
4848
draft: true
4949
prerelease: true
5050

NpgsqlRestClient/DefaultParser.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Security.Claims;
3-
using System.Text;
4-
using Microsoft.AspNetCore.Authorization.Infrastructure;
53
using Microsoft.Extensions.Primitives;
64
using NpgsqlRest;
75

@@ -22,43 +20,51 @@ public class DefaultResponseParser(
2220
private readonly Dictionary<string, StringValues>? customClaims = customClaims;
2321
private readonly Dictionary<string, string?>? customParameters = customParameters;
2422

23+
private const string @null = "null";
24+
private const char @open = '{';
25+
private const char @close = '}';
26+
private const char @quote = '"';
27+
private const char @arrOpen = '[';
28+
private const char @arrClose = ']';
29+
private const char @comma = ',';
30+
2531
public ReadOnlySpan<char> Parse(ReadOnlySpan<char> input, RoutineEndpoint endpoint, HttpContext context)
2632
{
2733
Dictionary<string, string> replacements = [];
2834

2935
if (userIdParameterName is not null)
3036
{
3137
var value = context.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
32-
replacements.Add(userIdParameterName, value is null ? "NULL" : string.Concat('"', value, '"'));
38+
replacements.Add(userIdParameterName, value is null ? @null : string.Concat(@quote, value, @quote));
3339
}
3440
if (userNameParameterName is not null)
3541
{
3642
var value = context.User.Identity?.Name;
37-
replacements.Add(userNameParameterName, value is null ? "NULL" : string.Concat('"', value, '"'));
43+
replacements.Add(userNameParameterName, value is null ? @null : string.Concat(@quote, value, @quote));
3844
}
3945
if (userRolesParameterName is not null)
4046
{
41-
var value = context.User.FindAll(c => string.Equals(c.Type, ClaimTypes.Role, StringComparison.Ordinal))?.Select(r => string.Concat('"', r.Value, '"'));
42-
replacements.Add(userRolesParameterName, value is null ? "NULL" : string.Concat('[', string.Join(',', value), ']'));
47+
var value = context.User.FindAll(c => string.Equals(c.Type, ClaimTypes.Role, StringComparison.Ordinal))?.Select(r => string.Concat(@quote, r.Value, @quote));
48+
replacements.Add(userRolesParameterName, value is null ? @null : string.Concat(@arrOpen, string.Join(@comma, value), @arrClose));
4349
}
4450
if (ipAddressParameterName is not null)
4551
{
4652
var value = App.GetClientIpAddress(context.Request);
47-
replacements.Add(ipAddressParameterName, value is null ? "NULL" : string.Concat('"', value, '"'));
53+
replacements.Add(ipAddressParameterName, value is null ? @null : string.Concat(@quote, value, @quote));
4854
}
4955
if (customClaims is not null)
5056
{
5157
foreach (var (key, value) in customClaims)
5258
{
5359
var claim = context.User.FindFirst(key);
54-
replacements.Add(key, claim is null ? "NULL" : string.Concat('"', claim.Value, '"'));
60+
replacements.Add(key, claim is null ? @null : string.Concat(@quote, claim.Value, @quote));
5561
}
5662
}
5763
if (customParameters is not null)
5864
{
5965
foreach (var (key, value) in customParameters)
6066
{
61-
replacements.Add(key, value is null ? "NULL" : string.Concat('"', value, '"'));
67+
replacements.Add(key, value is null ? @null : string.Concat(@quote, value, @quote));
6268
}
6369
}
6470
return FormatString(input, replacements);
@@ -86,7 +92,7 @@ public static ReadOnlySpan<char> FormatString(ReadOnlySpan<char> input, Dictiona
8692
for (int i = 0; i < inputLength; i++)
8793
{
8894
var ch = input[i];
89-
if (ch == '{')
95+
if (ch == @open)
9096
{
9197
if (inside is true)
9298
{
@@ -97,7 +103,7 @@ public static ReadOnlySpan<char> FormatString(ReadOnlySpan<char> input, Dictiona
97103
continue;
98104
}
99105

100-
if (ch == '}' && inside is true)
106+
if (ch == @close && inside is true)
101107
{
102108
inside = false;
103109
if (lookup.TryGetValue(input[(startIndex + 1)..i], out var value))
@@ -130,7 +136,7 @@ public static ReadOnlySpan<char> FormatString(ReadOnlySpan<char> input, Dictiona
130136
for(int i = 0; i < inputLength; i++)
131137
{
132138
var ch = input[i];
133-
if (ch == '{')
139+
if (ch == @open)
134140
{
135141
if (inside is true)
136142
{
@@ -142,7 +148,7 @@ public static ReadOnlySpan<char> FormatString(ReadOnlySpan<char> input, Dictiona
142148
continue;
143149
}
144150

145-
if (ch == '}' && inside is true)
151+
if (ch == @close && inside is true)
146152
{
147153
inside = false;
148154
if (lookup.TryGetValue(input[(startIndex + 1)..i], out var value))

NpgsqlRestClient/NpgsqlRestClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<InvariantGlobalization>true</InvariantGlobalization>
99
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
1010
<PublishAot>true</PublishAot>
11-
<Version>2.14.0</Version>
11+
<Version>2.15.0</Version>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

NpgsqlRestClient/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
2.14.0.0
2+
2.15.0.0
33
*/
44
{
55
//

client.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ Example: override Auth:CookieName config npgsqlrest --auth:cookiename=Test
9191

9292
## Changelog
9393

94+
## 2.15.0
95+
96+
- Versions:
97+
98+
```
99+
.NET 9.0.2
100+
Client Build 2.15.0.0
101+
Serilog.AspNetCore 9.0.0.0
102+
Npgsql 9.0.3.0
103+
NpgsqlRest 2.20.0.0
104+
NpgsqlRest.HttpFiles 1.3.0.0
105+
NpgsqlRest.TsClient 1.18.0.0
106+
NpgsqlRest.CrudSource 1.2.0.0
107+
```
108+
94109
## 2.14.0
95110

96111
This fix contains a fix for edge cases of parse method when using multiple curly braces.

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM ubuntu:25.04 AS builder
22
WORKDIR /app
33
RUN apt-get update && \
44
apt-get install -y --no-install-recommends wget ca-certificates && \
5-
wget https://github.com/vb-consulting/NpgsqlRest/releases/download/v2.20.0-client-v2.14.0/npgsqlrest-linux64 -O npgsqlrest && \
5+
wget https://github.com/vb-consulting/NpgsqlRest/releases/download/v2.20.0-client-v2.15.0/npgsqlrest-linux64 -O npgsqlrest && \
66
chmod +x npgsqlrest
77

88
FROM ubuntu:25.04

npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npgsqlrest",
3-
"version": "2.14.0",
3+
"version": "2.15.0",
44
"description": "Automatic REST API for PostgreSQL Databases Client Build",
55
"scripts": {
66
"postinstall": "node postinstall.js",

npm/postinstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const os = require("os");
66
const https = require("https");
77

88
const downloadDir = "../.bin/";
9-
const downloadFrom = "https://github.com/vb-consulting/NpgsqlRest/releases/download/v2.20.0-client-v2.14.0/";
9+
const downloadFrom = "https://github.com/vb-consulting/NpgsqlRest/releases/download/v2.20.0-client-v2.15.0/";
1010

1111
function download(url, to, done) {
1212
https.get(url, (response) => {

0 commit comments

Comments
 (0)