Skip to content

Commit

Permalink
Updating Unicode character processing for combining characters in IE
Browse files Browse the repository at this point in the history
In a previous revision, the IE driver was modified to normalize Unicode
strings that used combining characters to compose a single glyph when
sending keystrokes. This commit implements the reverse of that
operation when reading text data, decomposing the glyph into its
combining characters if required. This is a potential destablizing
change for text sequences that use combining characters, and care
should be taken by users to understand the potential differences if
handling text using such character combinations causes unexpected
results.
  • Loading branch information
jimevans committed Jan 24, 2019
1 parent ae76e25 commit 1df5cdf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
16 changes: 1 addition & 15 deletions cpp/iedriver/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,21 +598,7 @@ int InputManager::KeyUp(BrowserHandle browser_wrapper,

bool InputManager::IsSingleKey(std::wstring* input) {
bool is_single_key = true;
if (FALSE == ::IsNormalizedString(NormalizationC, input->c_str(), -1)) {
int required = ::NormalizeString(NormalizationC,
input->c_str(),
-1,
NULL,
0);
std::vector<wchar_t> buffer(required);
::NormalizeString(NormalizationC,
input->c_str(),
-1,
&buffer[0],
static_cast<int>(buffer.size()));
*input = &buffer[0];
}

StringUtilities::ComposeUnicodeString(input);
if (input->size() > 1) {
WORD combining_bitmask = C3_NONSPACING | C3_DIACRITIC | C3_VOWELMARK;
std::vector<WORD> char_types(input->size());
Expand Down
26 changes: 26 additions & 0 deletions cpp/iedriver/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,30 @@ std::wstring StringUtilities::CreateGuid() {
return returned_guid;
}

void StringUtilities::ComposeUnicodeString(std::wstring* input) {
StringUtilities::NormalizeUnicodeString(NormalizationC, input);
}

void StringUtilities::DecomposeUnicodeString(std::wstring* input) {
StringUtilities::NormalizeUnicodeString(NormalizationD, input);
}

void StringUtilities::NormalizeUnicodeString(NORM_FORM normalization_form,
std::wstring* input) {
if (FALSE == ::IsNormalizedString(normalization_form, input->c_str(), -1)) {
int required = ::NormalizeString(normalization_form,
input->c_str(),
-1,
NULL,
0);
std::vector<wchar_t> buffer(required);
::NormalizeString(normalization_form,
input->c_str(),
-1,
&buffer[0],
static_cast<int>(buffer.size()));
*input = &buffer[0];
}
}

} // namespace webdriver
13 changes: 11 additions & 2 deletions cpp/iedriver/StringUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,24 @@ class StringUtilities {
static std::wstring TrimLeft(const std::wstring& input);
static std::wstring Trim(const std::wstring& input);

static void ToBuffer(const std::string& input, std::vector<char>* buffer);
static void ToBuffer(const std::wstring& input, std::vector<wchar_t>* buffer);
static void ToBuffer(const std::string& input,
std::vector<char>* buffer);
static void ToBuffer(const std::wstring& input,
std::vector<wchar_t>* buffer);

static void ComposeUnicodeString(std::wstring* input);
static void DecomposeUnicodeString(std::wstring* input);

static void Split(const std::string& input,
const std::string& delimiter,
std::vector<std::string>* tokens);
static void Split(const std::wstring& input,
const std::wstring& delimiter,
std::vector<std::wstring>* tokens);

private:
static void NormalizeUnicodeString(NORM_FORM normalization_form,
std::wstring* input);
};

} // namespace webdriver
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/VariantUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ int VariantUtilities::ConvertVariantToJsonValue(IElementManager* element_manager
std::string string_value = "";
if (variant_value.bstrVal) {
std::wstring bstr_value = variant_value.bstrVal;
StringUtilities::DecomposeUnicodeString(&bstr_value);
string_value = StringUtilities::ToString(bstr_value);
}
*value = string_value;
Expand Down

0 comments on commit 1df5cdf

Please sign in to comment.