From 7a51007dc2c8628525c091c8cebe58a92d2008cb Mon Sep 17 00:00:00 2001 From: rameel Date: Sun, 11 Oct 2026 00:04:42 +0500 Subject: [PATCH 1/2] docs: clarify the request referrer remarks --- .../TagHelpers/HtmxRequestTagHelper.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Ramstack.HtmxToolkit/TagHelpers/HtmxRequestTagHelper.cs b/src/Ramstack.HtmxToolkit/TagHelpers/HtmxRequestTagHelper.cs index 21e5b2c..a5c791d 100644 --- a/src/Ramstack.HtmxToolkit/TagHelpers/HtmxRequestTagHelper.cs +++ b/src/Ramstack.HtmxToolkit/TagHelpers/HtmxRequestTagHelper.cs @@ -142,9 +142,17 @@ public HtmxRequestRedirect? Redirect /// Gets or sets the Fetch API referrer value for the request. /// /// - /// Supported only in HTMX 4.x. Accepts a same-origin URL, an empty string to omit - /// the referrer, or about:client to use the default referrer. - /// The separate Fetch API referrerPolicy option is not configured by this property. + /// Supported only in HTMX 4.x. + /// + /// Accepts a same-origin URL, an empty string to omit the referrer, + /// or about:client to use the default referrer. + /// The browser replaces a URL from another origin with the default referrer. + /// + /// + /// The separate Fetch API referrerPolicy option is not configured by this property. + /// Policy values such as no-referrer are treated as relative URLs; + /// use an empty string to omit the referrer. + /// /// [HtmlAttributeName(RequestReferrerAttributeName)] public string? Referrer From 671dad1d7bbbef82f9cc277cd9b0dd26f846b9db Mon Sep 17 00:00:00 2001 From: rameel Date: Sun, 11 Oct 2026 00:04:58 +0500 Subject: [PATCH 2/2] tag-helpers: test referrer values that Fetch accepts --- .../TagHelpers/HtmxRequestTagHelperTests.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxRequestTagHelperTests.cs b/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxRequestTagHelperTests.cs index 7a309dd..640e993 100644 --- a/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxRequestTagHelperTests.cs +++ b/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxRequestTagHelperTests.cs @@ -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; @@ -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); @@ -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)