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

feat(Validators): adds ability to validate invalid UTF-8 #784

Merged
merged 6 commits into from
Dec 28, 2016

Conversation

glowing-chemist
Copy link
Contributor

added validator_os

@coveralls
Copy link

coveralls commented Dec 25, 2016

Coverage Status

Coverage increased (+0.03%) to 91.142% when pulling a43f32c on glowing-chemist:master into eb1d79d on kbknapp:master.

@kbknapp
Copy link
Member

kbknapp commented Dec 27, 2016

Strange, I wonder why this is showing such a large diff? I'll take a look at this soon and should be able to merge for 2.20 👍

@kbknapp
Copy link
Member

kbknapp commented Dec 27, 2016

Aaah ok, I see why. In your fork, it looks like you've moved the files from src/* to src/src/*. Could you move them back to the src/ directory, and use the commit message feat(Validators): adds ability to validate invalid UTF-8 so that your commit will automatically be picked up by clog when I update my CHANGELOG.md

Thanks!

@glowing-chemist
Copy link
Contributor Author

OK thanks, yh I'll make the changes and resubmit :)

@glowing-chemist glowing-chemist changed the title added validator_os feat(Validators): adds ability to validate invalid UTF-8 Dec 27, 2016
@coveralls
Copy link

coveralls commented Dec 27, 2016

Coverage Status

Coverage decreased (-0.006%) to 91.108% when pulling f49fb88 on glowing-chemist:master into eb1d79d on kbknapp:master.

@@ -1525,6 +1525,7 @@ impl<'n, 'e> AnyArg<'n, 'e> for App<'n, 'e> {
fn num_vals(&self) -> Option<u64> { None }
fn possible_vals(&self) -> Option<&[&'e str]> { None }
fn validator(&self) -> Option<&Rc<Fn(String) -> StdResult<(), String>>> { None }
fn validator_os(&self) -> Option<&Rc<Fn(String) -> StdResult<(), String>>> { None }
Copy link
Member

Choose a reason for hiding this comment

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

This will need to be an OsString instead of a String to allow for invalid UTF-8

@@ -1533,6 +1533,11 @@ impl<'a, 'b> Parser<'a, 'b>
return Err(Error::value_validation(Some(arg), e, self.color()));
}
}
if let Some(vtor) = arg.validator_os() {
if let Err(e) = vtor(val.to_string_lossy().into_owned()) {
Copy link
Member

Choose a reason for hiding this comment

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

Once the String->OsString is done, this should be able to change to just vtor(val)

@kbknapp
Copy link
Member

kbknapp commented Dec 27, 2016

Whichever you're able to get working OsStr/&OsStr preferrably, or OsString (Although the returned value will be an OsString regardless, since we can't avoid that allocation) will need to replace each of the String instances, I just didn't want to duplicate the comments everywhere ;)

@glowing-chemist
Copy link
Contributor Author

I've changed all relevant Strings' to OsStrings and OsStr respectfully :)

@coveralls
Copy link

coveralls commented Dec 27, 2016

Coverage Status

Coverage decreased (-0.006%) to 91.108% when pulling 4723249 on glowing-chemist:master into eb1d79d on kbknapp:master.

Copy link
Member

@kbknapp kbknapp left a comment

Choose a reason for hiding this comment

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

Almost there! I think this last change will make it good for a merge 👍 Great work!

if let Err(e) = vtor(val.to_string_lossy().into_owned()) {
return Err(Error::value_validation(Some(arg), e, self.color()));
if let Err(e) = vtor(val) {
return Err(Error::value_validation(Some(arg), e.into_string().unwrap_or("error invalid UTF-8".to_string()), self.color()));
Copy link
Member

@kbknapp kbknapp Dec 28, 2016

Choose a reason for hiding this comment

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

This will change the users custom error message to this generic one if the user returns an OsString with invalid UTF-8 (which is almost expected because they're using validator_os in the first place). So we need to change this to something like &e.to_string_lossy()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yh had a bit of a brain fart there :p will fix that now

@coveralls
Copy link

coveralls commented Dec 28, 2016

Coverage Status

Coverage decreased (-0.09%) to 91.073% when pulling 17d70dc on glowing-chemist:master into 6fdd2f9 on kbknapp:master.

@coveralls
Copy link

coveralls commented Dec 28, 2016

Coverage Status

Coverage decreased (-0.09%) to 91.073% when pulling 17d70dc on glowing-chemist:master into 6fdd2f9 on kbknapp:master.

@kbknapp
Copy link
Member

kbknapp commented Dec 28, 2016

Look great! Once the tests pass, I'll merge 👍 Thanks again for tackling this!

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 91.045% when pulling a7186fa on glowing-chemist:master into e20009d on kbknapp:master.

1 similar comment
@coveralls
Copy link

coveralls commented Dec 28, 2016

Coverage Status

Coverage decreased (-0.09%) to 91.045% when pulling a7186fa on glowing-chemist:master into e20009d on kbknapp:master.

@kbknapp
Copy link
Member

kbknapp commented Dec 28, 2016

@homu r+

@homu
Copy link
Contributor

homu commented Dec 28, 2016

📌 Commit a7186fa has been approved by kbknapp

homu added a commit that referenced this pull request Dec 28, 2016
feat(Validators): adds ability to validate invalid UTF-8

added validator_os
homu added a commit that referenced this pull request Dec 28, 2016
feat(Validators): adds ability to validate invalid UTF-8

added validator_os
@homu
Copy link
Contributor

homu commented Dec 28, 2016

☀️ Test successful - status

@kbknapp kbknapp mentioned this pull request Dec 31, 2016
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.

4 participants