Skip to content

Extend validator support to local links - #88

Merged
bwplotka merged 2 commits into
bwplotka:mainfrom
saswatamcode:local-link-validator
Jul 12, 2022
Merged

bwplotka merged 2 commits into
bwplotka:mainfrom
saswatamcode:local-link-validator

Conversation

@saswatamcode

@saswatamcode saswatamcode commented Jul 12, 2022 •

Copy link
Copy Markdown
Collaborator

This PR extends validator support for local links.

Fixes #87.

@saswatamcode
saswatamcode requested a review from bwplotka July 12, 2022 10:32
@saswatamcode saswatamcode self-assigned this Jul 12, 2022

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some idea first to check (:

}

type IgnoreLocalValidator struct {
_regex *regexp.Regexp

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use exactly the same validator routines for local links, so we don't need to add any extra config bit.

Probably to ensure compatibility with current use cases, we might want to add special flag for it --enable-explicit-local-validators

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping it as a YAML config option instead, as we mention validators via that too. 🙂

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode
saswatamcode force-pushed the local-link-validator branch from 0ec996c to 2639800 Compare July 12, 2022 15:52
@saswatamcode saswatamcode changed the title Add support for local link validator Extend validator support to local links Jul 12, 2022

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one nit, not a blocker - feel free to merge.

// RoundTripValidator.IsValid returns true if url is checked by colly or it is a valid local link.
func (v RoundTripValidator) IsValid(k futureKey, r *validator) (bool, error) {
matches := remoteLinkPrefixRe.FindAllStringIndex(k.dest, 1)
if matches == nil && r.validateConfig.ExplicitLocalValidators {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to pack it in separate function? Looks like 1:1 to repetition.

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
return merr.Err()
}

func (v *validator) checkLocal(k futureKey) bool {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so much nicer!

@bwplotka
bwplotka merged commit 7dcc385 into bwplotka:main Jul 12, 2022
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.

Add config option to skip local link checks

2 participants

⌂ 换网址