Closed dylanmaryk closed 1 year ago
@nathancartlidge would appreciate your input if you're available 🙏
I can't immediately reproduce this:
@nathancartlidge here's one example: https://huxley2.azurewebsites.net/service/NDY5MTQ4NkNMUEhNSk1f
I'm also using the latest commits on my own fork that I use for my own Azure instance.
@nathancartlidge ah, is it maybe that serviceIdUrlSafe
is not using the new format?
@nathancartlidge serviceIdPercentEncoded
and serviceIdGuid
work fine for me so I think that's the issue
yep - that one doesn't work for me either, looks like a bug I introduced in the last commit unfortunately
This patch should fix it in the short term:
UTF8.GetString
instead of ToBase64String
@@ -95,25 +95,25 @@ namespace Huxley2.Services
// Encoder available as part of ASP.NET Core: Microsoft.Extensions.WebEncoders
// For more info read ASP.NET Core 2 High Performance (https://unop.uk/book) :)
- if (request.ServiceId.Length == 22)
+ if (request.ServiceId.Length == 20)
{
var sidBytes = WebEncoders.Base64UrlDecode(request.ServiceId);
- if (sidBytes.Length == 16)
+ if (sidBytes.Length == 15)
{
- request.ServiceId = Convert.ToBase64String(sidBytes);
+ request.ServiceId = System.Text.Encoding.UTF8.GetString(sidBytes);
}
}
- // If ID wasn't percent-encoded then it may be missing / + =
- // We try to fix it up if it isn't the correct length
- while (!request.ServiceId.EndsWith("==", StringComparison.OrdinalIgnoreCase))
- {
- request.ServiceId += "=";
- }
- while (request.ServiceId.Length < 24)
- {
- request.ServiceId = "/" + request.ServiceId;
- }
@nathancartlidge thanks! I can just use serviceIdGuid
instead, which seems to always be URL-safe already now? Feel free to submit a PR with the fix whenever you have time, but I can just use the alternative so I don't need it in a hurry.
all three other options (serviceId
, serviceIdPercentEncoded
, and serviceIdGuid
) should now be url-safe, so feel free to choose any of those!
I'll hopefully be able to get a commit out tonight to address this and the improvements from #14
I don't know if this might be something on National Rail's side, maybe something temporary, or something due to the recent service ID changes, but for any service ID I always get a crash here:
https://github.com/jpsingleton/Huxley2/blob/cc732c68fc5acc07f7f0190ffcaae75332c730ee/Huxley2/Services/ServiceDetailsService.cs#L119
Here is the full stack trace:
National Rail always return an error 500. Some of the additional details I get in Azure: