Whitespaces inside the quotation changes the behavior of `TZ="TIMEZONE"`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start in src/items/timezone.rs and review the existing TZ="..." parser and its current tests. Check the whitespace cases described in the issue, then verify that the parser accepts the proposed inner whitespace behavior without changing unrelated timezone forms; done means the relevant tests pass with the intended offsets.
Written by the indexing model from the issue text.
Description
This was a minor comment on https://github.com/uutils/parse_datetime/pull/232#issuecomment-3421283917 and it was suggested to create a separate issue for it
The following is the original copied here:
Hello, thanks to everybody for the great work.
I was studying this PR for a while and I was wondering that is there any reason (beyond performance) on why TZ="VALUE" is not relaxed with inner optional whitespaces (i.e TZ=" VALUE ")? Since such change passes all the current tests, this is a bit confusing to me.
This changes some behavior in an example like the following:
// prefixed whitespace
test(r#"TZ=" UTC-5:20:15""#, fixed_offset(0)); // current
test(r#"TZ=" UTC-5:20:15""#, fixed_offset(19215)); // with relaxed conditions
// prefixed whitespace
test(r#"TZ="UTC-5:20:15 ""#, Err(Backtrack(ContextError { context: [], cause: None }))); // current
test(r#"TZ="UTC-5:20:15 ""#, fixed_offset(19215)); // with relaxed conditions
Naturally, this can be generalized to the cases with :.
Whitespace relaxation can further improve in an unrelated example like: parse_datetime(" TZ=\"...\""). However in parse_datetime example, the user can easily just trim the input while removing the inner spaces of the quotation of this case is not as simple so that's why I think it's a quality improvement (if it is justified to begin with).
Example of changes that will relax this limitation:
diff --git a/src/items/timezone.rs b/src/items/timezone.rs
index 0414ee8..0009d17 100644
--- a/src/items/timezone.rs
+++ b/src/items/timezone.rs
@@ -16,6 +16,7 @@
use jiff::tz::{Offset, TimeZone};
use winnow::{
+ ascii::space0,
combinator::{alt, delimited, opt, preceded, repeat},
stream::AsChar,
token::{one_of, take_while},
@@ -25,7 +26,12 @@ use winnow::{
use super::primitive::{dec_uint, plus_or_minus};
pub(super) fn parse(input: &mut &str) -> ModalResult<TimeZone> {
- delimited("TZ=\"", preceded(opt(':'), alt((posix, iana))), '"').parse_next(input)
+ delimited(
+ ("TZ=\"", space0),
+ preceded(opt((':', space0)), alt((posix, iana))),
+ (space0, "\""),
+ )
+ .parse_next(input)
}
/// Parse a posix (proleptic) timezone string (e.g., "UTC7", "JST-9").
- Dominant language
- Rust
- Stars
- 37
- Forks
- 39
- Avg merge
- 17h 48m
- Merged PRs (30d)
- 8
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from uutils/parse_datetime
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
uutils/parse_datetime#317 ·
-
bug good first issue
Difficulty 3/5 1-2 days Newbie friendliness 65/100
uutils/parse_datetime#279 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
uutils/parse_datetime#160 · 10 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
uutils/parse_datetime#82 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
uutils/parse_datetime#36 · 4 comments · 1 reaction ·
All issues in uutils/parse_datetime
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100