You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@answer.apache.org by "ferhatelmas (via GitHub)" <gi...@apache.org> on 2026/08/02 14:36:16 UTC

[PR] test(converter): pin renderLinkIsUrl behavior [answer]

ferhatelmas opened a new pull request, #1565:
URL: https://github.com/apache/answer/pull/1565

   Add a table-driven test covering the markdown link destination check
   before replacing the govalidator dependency with stdlib logic.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org


Re: [PR] test(converter): pin renderLinkIsUrl behavior [answer]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1565:
URL: https://github.com/apache/answer/pull/1565#discussion_r3719683753


##########
pkg/converter/markdown_test.go:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package converter
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRenderLinkIsUrl(t *testing.T) {
+	cases := []struct {
+		name string
+		in   string
+		want bool
+	}{
+		{"absolute http URL", "http://example.com/path?q=1#f", true},
+		{"absolute https URL", "https://example.com", true},
+		{"ftp URL", "ftp://example.com/file", true},
+		{"uppercase scheme and host", "HTTP://EXAMPLE.COM", false},
+		{"bare domain", "example.com", true},
+		{"bare domain with path", "example.com/questions/123", true},
+		{"www subdomain", "www.example.com", true},
+		{"bare IP", "10.0.0.1", true},
+		{"IP with port and path", "10.0.0.1:8080/a", true},
+		{"host with port", "localhost:8080", true},
+		{"domain with port and path", "example.com:8080/x", true},
+		{"IPv6 with port", "[::1]:8080", true},
+		{"userinfo", "user:pass@example.com", true},
+		{"mailto", "mailto:a@b.com", true},
+		{"email-like destination", "a@b.co", true},
+		{"userinfo without scheme", "user@h.co", true},
+		{"trailing dot FQDN", "example.com.", true},
+		{"empty", "", false},
+		{"single word", "foo", false},
+		{"path segment no dot", "questions/123", false},
+		{"absolute path", "/questions/123", true},
+		{"scheme-less authority path", "//cdn.example.com/x", true},
+		{"anchor", "#section", false},
+		{"leading dot", ".hidden", false},
+		{"javascript scheme", "javascript:alert(1)", false},
+		{"tel scheme", "tel:+1234", false},
+		{"host with leading dot", "http://.example.com", false},
+		{"trailing colon", "example.com:", false},
+		{"single label with scheme", "http://localhost", true},
+		{"single label no scheme no port", "localhost", false},
+		{"not a url", "not a url", false},
+		{"whitespace in path", "h.co/p q", false},
+		{"label with leading hyphen", "-ex.com", false},
+		{"label with trailing hyphen", "ex-.com", false},
+		{"invalid IPv4 quad", "999.1.1.1", false},
+		{"IPv4 with leading zeros", "01.2.3.4", false},
+		{"three letter domain", "a.b", false},

Review Comment:
   The case name doesn’t match the input (`a.b` is not a “three letter domain”). Rename the case to accurately describe what’s being tested (e.g., short/one-letter labels), so failures are easier to interpret.



##########
pkg/converter/markdown_test.go:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package converter
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRenderLinkIsUrl(t *testing.T) {
+	cases := []struct {
+		name string
+		in   string
+		want bool
+	}{
+		{"absolute http URL", "http://example.com/path?q=1#f", true},
+		{"absolute https URL", "https://example.com", true},
+		{"ftp URL", "ftp://example.com/file", true},
+		{"uppercase scheme and host", "HTTP://EXAMPLE.COM", false},
+		{"bare domain", "example.com", true},
+		{"bare domain with path", "example.com/questions/123", true},
+		{"www subdomain", "www.example.com", true},
+		{"bare IP", "10.0.0.1", true},
+		{"IP with port and path", "10.0.0.1:8080/a", true},
+		{"host with port", "localhost:8080", true},
+		{"domain with port and path", "example.com:8080/x", true},
+		{"IPv6 with port", "[::1]:8080", true},
+		{"userinfo", "user:pass@example.com", true},
+		{"mailto", "mailto:a@b.com", true},
+		{"email-like destination", "a@b.co", true},
+		{"userinfo without scheme", "user@h.co", true},
+		{"trailing dot FQDN", "example.com.", true},
+		{"empty", "", false},
+		{"single word", "foo", false},
+		{"path segment no dot", "questions/123", false},
+		{"absolute path", "/questions/123", true},
+		{"scheme-less authority path", "//cdn.example.com/x", true},
+		{"anchor", "#section", false},
+		{"leading dot", ".hidden", false},
+		{"javascript scheme", "javascript:alert(1)", false},
+		{"tel scheme", "tel:+1234", false},
+		{"host with leading dot", "http://.example.com", false},
+		{"trailing colon", "example.com:", false},
+		{"single label with scheme", "http://localhost", true},
+		{"single label no scheme no port", "localhost", false},
+		{"not a url", "not a url", false},
+		{"whitespace in path", "h.co/p q", false},
+		{"label with leading hyphen", "-ex.com", false},
+		{"label with trailing hyphen", "ex-.com", false},
+		{"invalid IPv4 quad", "999.1.1.1", false},
+		{"IPv4 with leading zeros", "01.2.3.4", false},
+		{"three letter domain", "a.b", false},
+	}
+	r := &DangerousHTMLRenderer{}
+	for _, tc := range cases {
+		t.Run(tc.name, func(t *testing.T) {
+			assert.Equal(t, tc.want, r.renderLinkIsUrl(tc.in))
+		})
+	}

Review Comment:
   The subtest closure captures the loop variable `tc`. While it’s safe as written (no `t.Parallel()`), this becomes a common source of bugs if parallelism is added later. Consider shadowing `tc := tc` inside the loop (or passing `tc` into the closure) to make this future-proof.



##########
pkg/converter/markdown_test.go:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package converter
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRenderLinkIsUrl(t *testing.T) {

Review Comment:
   Go naming conventions typically capitalize common initialisms (URL). Consider renaming the test to `TestRenderLinkIsURL` for consistency/readability.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org


Re: [PR] test(converter): pin renderLinkIsUrl behavior [answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars merged PR #1565:
URL: https://github.com/apache/answer/pull/1565


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org