-
Couldn't load subscription status.
- Fork 1.2k
[release/10.0.1xx] URL-encode scoped CSS Link headers for non-ASCII project names #51039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
0e1881a
dec378b
f44a784
21a64d7
8555444
95dcef5
8704787
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,8 @@ public override bool Execute() | |
| endpoint.AssetFile = asset.ResolvedAsset.ComputeTargetPath("", '/', StaticWebAssetTokenResolver.Instance); | ||
| endpoint.Route = route; | ||
|
|
||
| EncodeLinkHeadersIfNeeded(endpoint); | ||
|
|
||
| Log.LogMessage(MessageImportance.Low, "Including endpoint '{0}' for asset '{1}' with final location '{2}'", endpoint.Route, endpoint.AssetFile, asset.TargetPath); | ||
| } | ||
|
|
||
|
|
@@ -137,6 +139,48 @@ public override bool Execute() | |
| return !Log.HasLoggedErrors; | ||
| } | ||
|
|
||
| private static void EncodeLinkHeadersIfNeeded(StaticWebAssetEndpoint endpoint) | ||
| { | ||
| for (var i = 0; i < endpoint.ResponseHeaders.Length; i++) | ||
| { | ||
| ref var header = ref endpoint.ResponseHeaders[i]; | ||
| if (!string.Equals(header.Name, "Link", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| continue; | ||
| } | ||
| var headerValues = header.Value.Split([','], StringSplitOptions.RemoveEmptyEntries); | ||
lewing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (var j = 0; j < headerValues.Length; j++) | ||
| { | ||
| ref var value = ref headerValues[j]; | ||
| value = EncodeHeaderValue(value); | ||
| } | ||
| header.Value = string.Join(",", headerValues); | ||
| } | ||
| } | ||
|
|
||
| private static string EncodeHeaderValue(string header) | ||
| { | ||
| var index = header.IndexOf('<'); | ||
| if (index == -1) | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, better to make this |
||
| return header; | ||
| } | ||
| index++; | ||
| var endIndex = header.IndexOf('>', index); | ||
| if (endIndex == -1) | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar |
||
| return header; | ||
| } | ||
| var link = header.AsSpan(index, endIndex - index).ToString(); | ||
| var segments = link.Split('/'); | ||
| for (var j = 0; j < segments.Length; j++) | ||
| { | ||
| segments[j] = System.Net.WebUtility.UrlEncode(segments[j]); | ||
| } | ||
| var encoded = string.Join("/", segments); | ||
| return $"{header.Substring(0, index)}{encoded}{header.Substring(endIndex)}"; | ||
| } | ||
|
|
||
| private static (string, string[]) ParseAndSortPatterns(string patterns) | ||
| { | ||
| if (string.IsNullOrEmpty(patterns)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.