Skip to content
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

add TrimSuffix to the function map #10

Merged
merged 2 commits into from
Dec 1, 2022

Conversation

vielmetti
Copy link
Contributor

Adds strings.TrimSuffix to the function map, enabling it to be used in URL definitions.

This accompanies the discussion in #9 and is motivated by the browser misfeature of my Safari instance, which fails to recognize a local domain URL as a URL unless it has a trailing slash. The intended use of this function is to trim that trailing slash.

(There is most certainly some more elegant way to do this, but as a start this is the one-line fix suggested by @willnorris that lets me make forward progress.)

Adds strings.TrimSuffix to the function map, enabling it to be used in URL definitions.
@willnorris
Copy link
Member

Would you mind also adding a test case in https://github.com/tailscale/golink/blob/main/golink_test.go ? I'm also happy to add one myself.

@willnorris
Copy link
Member

(in those tests, the leftover path is called "remainder". I just never renamed that apparently)

@willnorris
Copy link
Member

hmm... I dont' know if I can suggest changes on a file that you didn't already touch, so the additional test case would just be:

		{
			name:      "template-with-trimsuffix-func",
			long:      `http://host.com/{{TrimSuffix .Path "/"}}`,
			remainder: "a/",
			want:      "http://host.com/a",
		},

As told by @willnorris , this tests the TrimSuffix function.
@vielmetti
Copy link
Contributor Author

Test added as requested.

@willnorris
Copy link
Member

Awesome, thanks! Looks great.

@willnorris willnorris merged commit 0755e37 into tailscale:main Dec 1, 2022
willnorris added a commit that referenced this pull request Sep 19, 2024
Updates #10

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <[email protected]>
willnorris added a commit that referenced this pull request Sep 19, 2024
We need TrimPrefix and ToUpper for some links at Tailscale, and might as
well ToLower as well at that point.

Updates #10

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <[email protected]>
willnorris added a commit that referenced this pull request Sep 19, 2024
We need TrimPrefix and ToUpper for some links at Tailscale, and might as
well ToLower as well at that point.

Updates #10

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <[email protected]>
willnorris added a commit that referenced this pull request Sep 19, 2024
We need TrimPrefix and ToUpper for some links at Tailscale, and might as
well ToLower as well at that point.

Updates #10

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <[email protected]>
willnorris added a commit that referenced this pull request Sep 20, 2024
We need TrimPrefix and ToUpper for some links at Tailscale, and might as
well ToLower as well at that point.

Updates #10

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants