Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Ramstack.HtmxToolkit/TagHelpers/HtmxRequestTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,17 @@ public HtmxRequestRedirect? Redirect
/// Gets or sets the Fetch API <c>referrer</c> value for the request.
/// </summary>
/// <remarks>
/// Supported only in HTMX 4.x. Accepts a same-origin URL, an empty string to omit
/// the referrer, or <c>about:client</c> to use the default referrer.
/// The separate Fetch API <c>referrerPolicy</c> option is not configured by this property.
/// <para>Supported only in HTMX 4.x.</para>
/// <para>
/// Accepts a same-origin URL, an empty string to omit the referrer,
/// or <c>about:client</c> to use the default referrer.
/// The browser replaces a URL from another origin with the default referrer.
/// </para>
/// <para>
/// The separate Fetch API <c>referrerPolicy</c> option is not configured by this property.
/// Policy values such as <c>no-referrer</c> are treated as relative URLs;
/// use an empty string to omit the referrer.
/// </para>
/// </remarks>
[HtmlAttributeName(RequestReferrerAttributeName)]
public string? Referrer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task ProcessAsync_SerializesHtmx4RequestConfiguration()
helper.NoHeaders = true;
helper.Cache = HtmxRequestCache.NoCache;
helper.Redirect = HtmxRequestRedirect.Manual;
helper.Referrer = "no-referrer";
helper.Referrer = "/reports";
helper.Integrity = "sha384-example";
helper.Validate = true;

Expand All @@ -110,7 +110,7 @@ public async Task ProcessAsync_SerializesHtmx4RequestConfiguration()
Assert.That(json["credentials"].GetString(), Is.EqualTo("omit"));
Assert.That(json["cache"].GetString(), Is.EqualTo("no-cache"));
Assert.That(json["redirect"].GetString(), Is.EqualTo("manual"));
Assert.That(json["referrer"].GetString(), Is.EqualTo("no-referrer"));
Assert.That(json["referrer"].GetString(), Is.EqualTo("/reports"));
Assert.That(json["integrity"].GetString(), Is.EqualTo("sha384-example"));
Assert.That(json["validate"].GetBoolean(), Is.True);
Assert.That(json.ContainsKey("noHeaders"), Is.False);
Expand Down Expand Up @@ -185,6 +185,18 @@ public async Task ProcessAsync_Htmx4_OmitsClearedCacheAndRedirectModes()
Assert.That(output.Attributes["hx-config"]!.Value.ToString(), Is.EqualTo("{\"timeout\":500}"));
}

[Test]
public async Task ProcessAsync_Htmx4_SerializesEmptyReferrer()
{
var output = TestHelper.CreateTagHelperOutput();
var helper = CreateHelper(HtmxTargetVersion.V4);
helper.Referrer = "";

await helper.ProcessAsync(TestHelper.CreateTagHelperContext(), output);

Assert.That(output.Attributes["hx-config"]!.Value.ToString(), Is.EqualTo("{\"referrer\":\"\"}"));
}

[TestCase(HtmxTargetVersion.V1)]
[TestCase(HtmxTargetVersion.V2)]
public async Task ProcessAsync_OmitsCacheAndRedirectModesForPriorVersions(HtmxTargetVersion version)
Expand Down
Loading