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

Validate image existence before post or preview #998

Merged
merged 1 commit into from
May 16, 2021

Conversation

paskal
Copy link
Collaborator

@paskal paskal commented May 13, 2021

That should cover the case when an image is posted after it cleaned up or the URL is altered by mistake: in case image belongs to this site, it should be working at the time of preview or comment post.

@paskal paskal requested a review from umputun May 13, 2021 01:07
Copy link
Owner

@umputun umputun left a comment

Choose a reason for hiding this comment

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

LGTM. Won't provide much details to the user (like what picture caused a problem in case of multiple) but won't hurt for sure

Copy link
Owner

@umputun umputun left a comment

Choose a reason for hiding this comment

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

oops, noticed image related tested failed

@paskal paskal force-pushed the dverhoturov/validate_image_before_post branch 2 times, most recently from 241b50c to 8aba64d Compare May 13, 2021 22:37
@coveralls
Copy link

coveralls commented May 13, 2021

Pull Request Test Coverage Report for Build 845751851

  • 31 of 37 (83.78%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 83.586%

Changes Missing Coverage Covered Lines Changed/Added Lines %
backend/app/rest/api/rest_private.go 9 12 75.0%
backend/app/rest/api/rest_public.go 10 13 76.92%
Totals Coverage Status
Change from base Build 840463573: -0.02%
Covered Lines: 5413
Relevant Lines: 6476

💛 - Coveralls

@paskal paskal force-pushed the dverhoturov/validate_image_before_post branch 3 times, most recently from b20ca23 to be7fe0f Compare May 14, 2021 10:03
@paskal paskal marked this pull request as draft May 14, 2021 10:06
@paskal paskal force-pushed the dverhoturov/validate_image_before_post branch from be7fe0f to f00d433 Compare May 15, 2021 21:54
@paskal paskal marked this pull request as ready for review May 15, 2021 21:55
@paskal
Copy link
Collaborator Author

paskal commented May 15, 2021

@umputun now it's properly working both in reality and tests, please review and merge if everything is OK.

return
}
ids = append(ids, imgID)
}
}
})
if err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure if the error check here safe/correct. I mean, extraction before this change worked even for partially valid document and returned some images anyway. I think it was intentional, and now we may have all or nothing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now it's all or nothing, but there is no way you get an error on submitImages (the only function using that function before the PR) after comment sending now because post sending calls the same function and won't allow posting incorrect images.

I don't recall an intention of ignoring the error when I wrote cache image extraction, when I was preparing that PR I was surprised by the bare return inside that function returning null instead of err

Copy link
Owner

Choose a reason for hiding this comment

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

hmm, the function ExtractPictures returned an error only in one case - goquery.NewDocumentFromReader failed. Everything else was forgiving and func tried to extract as many pictures as possible from the comment. After this change instead of valid pictures, submitImages won't get anything if one of the images failed, and idsFn will return an empty slice. Are you sure this behavior valid?

Is this change even relevant to the PR? I don't see how changing the logic of ExtractPictures is necessary for the proper validation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without that change, we do not validate cached images. But they are available in the comment only on edit and not on the post and we don't validate edits in this PR.

I think you are right and it would be better to revert that function change and document it better instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now, as we talk about it, I started wondering if we should return the error at all: it's confusing to have an error of HTML parsing returned to the caller but cached image parsing errors hidden in the code. Making it errorless will clarify the intention of returning ids at any cost, what do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

the error it returns now is kind of "panic case, should never happen". Logging this thing as we do is ok strategy, just in case.

@paskal paskal force-pushed the dverhoturov/validate_image_before_post branch from f00d433 to 32493d9 Compare May 16, 2021 09:46
@paskal paskal requested a review from umputun May 16, 2021 09:58
@umputun umputun merged commit fe716b0 into master May 16, 2021
@umputun umputun deleted the dverhoturov/validate_image_before_post branch May 16, 2021 18:50
@paskal paskal added this to the v1.9 milestone Jan 15, 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.

3 participants