Closed onionltd closed 2 years ago
This seems to do way more and adds a badly named "utils" pkg ...
On Fri, 29 Jul 2022, 20:24 Onion Ltd, @.***> wrote:
If set, the hook overrides the default IsSafeURL and allows users of the library to decide which URIs are safe to keep. This asked for some refactoring which I made into separate commits. I think the PR is quite big and thought it would be best to review it as two separate PRs. However, I didn't communicate my intentions and this was met with misunderstanding https://github.com/gomarkdown/markdown/pull/251. This time around I'm submitting the branch as is. I have left some TODOs which I will take care once this gets some eyeballs.
You can view, comment on, or merge this pull request online at:
https://github.com/gomarkdown/markdown/pull/252 Commit Summary
- b921cc5 https://github.com/gomarkdown/markdown/pull/252/commits/b921cc5b48cf6958b8069e7b96fd2cff05f81c92 move shared functions in utils package
- cafba03 https://github.com/gomarkdown/markdown/pull/252/commits/cafba03451f043000dfb0dd0205ef112a7c69be0 add IsMailto in utils
- cd99da0 https://github.com/gomarkdown/markdown/pull/252/commits/cd99da0e4b15e2847e5b9454a199aa2d7b014b20 add IsSafeURLOverride
File Changes
(11 files https://github.com/gomarkdown/markdown/pull/252/files)
- M helpers_test.go https://github.com/gomarkdown/markdown/pull/252/files#diff-62f46d82044a129997b958c0f7eb6a95038395d337176418d3dffae98d9332d1 (19)
- M html/renderer.go https://github.com/gomarkdown/markdown/pull/252/files#diff-3649d9415fd7cf34f0ded60c757bedd8a3f89c59f8d04b799e246e0e730a17d4 (106)
- M html/smartypants.go https://github.com/gomarkdown/markdown/pull/252/files#diff-0505b24fdef4f3c6f5cfd79dbc6636f6d3c07b28f1be70c72d070bef79dca72f (36)
- M inline_test.go https://github.com/gomarkdown/markdown/pull/252/files#diff-34907f8c63a83fb9f03d2e5858f19c5b94694db84c51e3d224f6fcd7ccd1fd59 (6)
- A internal/utils/utils.go https://github.com/gomarkdown/markdown/pull/252/files#diff-a7cadd8b7616e655fd258138320b33eb96f7cce8e8663ec92651f49ce07df000 (65)
- M internal/valid/valid.go https://github.com/gomarkdown/markdown/pull/252/files#diff-4e13ad7efeb8af61038ca5c03abce7a1c9f90d809c7eb162149f2d620cad2fa5 (36)
- M parser/block.go https://github.com/gomarkdown/markdown/pull/252/files#diff-cacf85204747e5c544be1eb0f516555e2a928c8998bb0048d15a6a1ea7d1b1cb (12)
- M parser/caption.go https://github.com/gomarkdown/markdown/pull/252/files#diff-0c23d9456c43d2715783451a929af32bb90c869678147fbcd9a793cb89ebc91e (4)
- M parser/inline.go https://github.com/gomarkdown/markdown/pull/252/files#diff-1b51aa68caff46e11f8bbf15253c1a2e3868716774dc2cb1bb1d2d69ca3a8f41 (82)
- M parser/parser.go https://github.com/gomarkdown/markdown/pull/252/files#diff-e7aabff4498aa61c581fe6fd5c90c50da24b02b88f32d75238a5dc37edaaa794 (42)
- M parser/ref.go https://github.com/gomarkdown/markdown/pull/252/files#diff-b30fa15dadd4a7eb3bb1bd6ce6ac98bf36642f5500fa09f836fef65194549411 (4)
Patch Links:
- https://github.com/gomarkdown/markdown/pull/252.patch
- https://github.com/gomarkdown/markdown/pull/252.diff
— Reply to this email directly, view it on GitHub https://github.com/gomarkdown/markdown/pull/252, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACWIW2KJ2QHUZMQF2QZM2LVWQOV3ANCNFSM55BSKX5Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>
This seems to do way more and adds a badly named "utils" pkg ...
I saw your comment. I don't mind splitting the code in two separate packages textutil
and astutil
, if that's what you think is the right way.
It's not so much about the name but the whole idea of refactoring into internal package and bundling that change with unrelated change for IsSafeURL
Yes, we have a little bit of code duplication and that's unfortunate. But also "A little copying is better than a little dependency." as per https://go-proverbs.github.io/
On the whole, I don't think the amount and nature of duplicated code warrants this refactoring. Especially given that I consider this library more or less done i.e. neither me nor anyone else is actively working on making significant changes.
Bottom line: making IsSafeURL
configurable is an acceptable addition but please undo the refactoring into internal package.
BTW: I'm a minimalist, pragmatist and not dogmatist.
Minimalist: less code is better than more code. Less packages is better than more packages.
Pragmatist and not dogmatist: things don't have to be perfect.
In retrospect, I probably made a mistake in splitting this code into multiple packages. Because less packages is better than more packages. It's too late to change that.
As it pertains to the little code duplication we have: I don't want to add more packages because I'm a minimalist.
We have a "leaf" package ast
where we can put functions that are used in more than one package. Does isAlnum
belong, logically, in ast
package? It doesn't. But I'm a pragmatist and I'm ok with putting it there..
Either way such refactoring doesn't belong in IsSafeURL
change.
Thank you for your feedback. I have dropped the commits that do not pertain to the subject. There isn't as much code duplication after all.
Thanks!
If set, the hook overrides the default
IsSafeURL
and allows users of the library to decide which URIs are safe to keep. This asked for some refactoring which I made into separate commits. I think the PR is quite big and thought it would be best to review it as two separate PRs. However, I didn't communicate my intentions and this was met with misunderstanding. This time around I'm submitting the branch as is. I have left some TODOs which I will take care once this gets some eyeballs.