-
Notifications
You must be signed in to change notification settings - Fork 175
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
Fix transliterator fallback loading #5489
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some commentary
)), | ||
s => Err(DataError::custom("unavailable transliterator").with_debug_context(s)), | ||
))), | ||
_ => None, | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion (optional): invert load_with_override
to also return Option<Result>
.strip_prefix("x-") | ||
.map(|special| Transliterator::load_special(special, normalizer_provider)) | ||
.and_then(|special| Transliterator::load_special(special, normalizer_provider)) | ||
// b) the user-provided override | ||
.or_else(|| Transliterator::load_with_override(&dep, lookup?).transpose()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the logic here:
dep.strip_prefix
returnsOption<...>
.and_then
now resolves toOption<Result<...>>
. Will beNone
if eitherstrip_prefix
failed or ifload_special
did not match anything. OK so far..or_else
is skipped ifload_special
returnedSome
. Otherwise, it returnsOption<Result<...>>
, with aNone
value if there was no override. Still OK..unwrap_or_else
returns theResult<...>
or else callsload_rbt
and propagates the result from that.
Previously, the behavior was:
dep.strip_prefix
returnsOption<...>
.map
resolves toOption<Result<...>>
. Will beNone
only if strip_prefix failed.- …
So the difference is that we never previously called load_with_override
or load_rbt
if the ID started with the string x-
. As far as I can tell, the x-
gets added here:
unparsed.replace_range(0..0, "x-"); |
Note that load_with_override
already fails unconditionally on x-
because it needs the ID to be valid BCP-47. However, load_rbt
just takes the ID and stuffs it into the DataMarkerAttributes.
Basically, I think this means that a string referencing a transliterator ID that doesn't have a BCP-47 alias, such as "::Lower" (which appears to become "x-any-lower"), could now be returned by a data provider that responds to requests for "und/x-any-lower" (using "/" as the data marker delimiter). So, that is the nature of the behavior change.
Without this change, it is required to always add a BCP-47 alias mappings for any transliterator IDs that are not in the built-in set.
ad7f42c
to
b6d91be
Compare
b6d91be
to
5454a51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Were you comfortable with the observations from the comments I left above?
Yes |
#5468