-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lint issues Wrap json.Unmarshall() errors in urls.go Bump version 0.83.9 -> 0.83.10
- Loading branch information
1 parent
7dfeda1
commit 1efe023
Showing
4 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.83.9 | ||
0.83.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package urls | ||
|
||
import ( | ||
"strings" | ||
"unicode/utf8" | ||
) | ||
|
||
const ( | ||
htmlTagStart = 60 // Unicode `<` | ||
htmlTagEnd = 62 // Unicode `>` | ||
) | ||
|
||
// Taken from https://stackoverflow.com/a/64701836 | ||
// Aggressively strips HTML tags from a string. | ||
// It will only keep anything between `>` and `<`. | ||
func stripHTMLTags(s string) string { | ||
// Setup a string builder and allocate enough memory for the new string. | ||
var builder strings.Builder | ||
builder.Grow(len(s) + utf8.UTFMax) | ||
|
||
in := false // True if we are inside an HTML tag. | ||
start := 0 // The index of the previous start tag character `<` | ||
end := 0 // The index of the previous end tag character `>` | ||
|
||
for i, c := range s { | ||
// If this is the last character and we are not in an HTML tag, save it. | ||
if (i+1) == len(s) && end >= start { | ||
builder.WriteString(s[end:]) | ||
} | ||
|
||
// Keep going if the character is not `<` or `>` | ||
if c != htmlTagStart && c != htmlTagEnd { | ||
continue | ||
} | ||
|
||
if c == htmlTagStart { | ||
// Only update the start if we are not in a tag. | ||
// This make sure we strip out `<<br>` not just `<br>` | ||
if !in { | ||
start = i | ||
} | ||
in = true | ||
|
||
// Write the valid string between the close and start of the two tags. | ||
builder.WriteString(s[end:start]) | ||
continue | ||
} | ||
// else c == htmlTagEnd | ||
in = false | ||
end = i + 1 | ||
} | ||
s = builder.String() | ||
return s | ||
} |