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

Code coverage for >+ #44

Closed
jonasfj opened this issue Mar 6, 2023 · 3 comments · Fixed by #87
Closed

Code coverage for >+ #44

jonasfj opened this issue Mar 6, 2023 · 3 comments · Fixed by #87
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) type-enhancement A request for a change that isn't a bug

Comments

@jonasfj
Copy link
Member

jonasfj commented Mar 6, 2023

We have no test that exercise this code:
https://coveralls.io/builds/57565406/source?filename=lib%2Fsrc%2Fstrings.dart#L103

That might be a good idea to have some tests for. Maybe there is bugs?

@jonasfj jonasfj added type-enhancement A request for a change that isn't a bug good first issue A good starting issue for contributors (issues with this label will appear in /contribute) labels Mar 6, 2023
@MikiPAUL
Copy link
Contributor

MikiPAUL commented Mar 7, 2023

Hi @jonasfj, I think this code won't execute under any circumstances. Because the string has leading or trailing spaces, it is interpreted as PLAIN.

// Strings with only white spaces will cause a misparsing
if (value.value.trim().length == value.value.length &&
value.value.length != 0) {
if (value.style == ScalarStyle.FOLDED) {
return _tryYamlEncodeFolded(value.value, indentation, lineEnding);
}
if (value.style == ScalarStyle.LITERAL) {
return _tryYamlEncodeLiteral(value.value, indentation, lineEnding);
}
}
}
return _tryYamlEncodePlain(value.value);
}

@jonasfj
Copy link
Member Author

jonasfj commented Mar 7, 2023

Hmm, that might make sense. I guess it's rare that something starts with whitespace -- and in such circumstances it might be simpler to just fallback to a safer string style.

I wonder if we should refactor the string handling. I probably don't have too good an overview.

Perhaps a good start is to write down what string styles we have, where they can be used, and what limits they have.

Some strings styles can't represent any string.

@setcy
Copy link

setcy commented Mar 8, 2023

I think if a string does not contain special characters, it can be representable as both a folded string and a literal string.

For strings that begin with spaces or line breaks, we need to use block styles with indication indicators to implement it. By using this method, even a single space can be represented.

Therefore, if we improve _tryYamlEncodeFolded and _tryYamlEncodeLiteral, the sentence if (value.value.trim().length == value.value.length && value.value.length != 0) will be unnecessary.

However, cases where strings begin with spaces or line breaks are relatively rare, and some interpreters may parse them incorrectly. If considering a safer approach, falling back to a more secure string style will never be wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants