.../Edit/FileBuffer.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2339
Currently it is not possible to add letters outside the range
U+0020 - U+007F to a file using the edit command.
In Unicode the following are control characters:
* U+0000—U+001F (C0 controls)
* U+007F (DEL)
* U+0080—U+009F (C1 controls).
For reference see:
* https://unicode.org/charts/PDF/U0000.pdf
* https://unicode.org/charts/PDF/U0080.pdf
So the characters we should exclude from the file buffer are:
U+0000 - U+001f, U+007f - U009F
Allow all other characters as input to the file buffer in Unicode mode.
Allow only ASCII characters as input in ASCII mode.
When saving a file in ASCII mode replace non-ASCII characters by a question
mark ('?').
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
Resent due to a typo in Limings email-address.
---
.../Edit/FileBuffer.c | 21 +++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
index fd324cc4a8..12235e4e4b 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
@@ -1360,6 +1360,8 @@ GetNewLine (
/**
Change a Unicode string to an ASCII string.
+ Non-ASCII characters are replaced by '?'.
+
@param[in] UStr The Unicode string.
@param[in] Length The maximum size of AStr.
@param[out] AStr ASCII string to pass out.
@@ -1378,8 +1380,12 @@ UnicodeToAscii (
//
// just buffer copy, not character copy
//
- for (Index = 0; Index < Length; Index++) {
- *AStr++ = (CHAR8) *UStr++;
+ for (Index = 0; Index < Length; Index++, UStr++) {
+ if (*UStr < 0x80) {
+ *AStr++ = (CHAR8) *UStr;
+ } else {
+ *AStr++ = '?';
+ }
}
return Index;
@@ -2154,9 +2160,16 @@ FileBufferDoCharInput (
default:
//
- // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
+ // Do not add Unicode control characters to the file buffer:
+ //
+ // * U+0000-U+001f (C0 controls)
+ // * U+007f (DEL)
+ // * U+0080-U+009f (C1 controls)
+ //
+ // Do not add non-ASCII characters in ASCII mode.
//
- if (Char > 127 || Char < 32) {
+ if (Char < 0x20 || (Char >= 0x7f &&
+ (Char <= 0x9f || FileBuffer.FileType == FileTypeAscii))) {
Status = StatusBarSetStatusString (L"Unknown Command");
} else {
Status = FileBufferAddChar (Char);
--
2.24.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#51207): https://edk2.groups.io/g/devel/message/51207
Mute This Topic: https://groups.io/mt/61872994/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 11/24/19 11:37, Heinrich Schuchardt via Groups.Io wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2339 > > Currently it is not possible to add letters outside the range > U+0020 - U+007F to a file using the edit command. > > In Unicode the following are control characters: > > * U+0000—U+001F (C0 controls) > * U+007F (DEL) > * U+0080—U+009F (C1 controls). > > For reference see: > > * https://unicode.org/charts/PDF/U0000.pdf > * https://unicode.org/charts/PDF/U0080.pdf > > So the characters we should exclude from the file buffer are: > U+0000 - U+001f, U+007f - U009F > > Allow all other characters as input to the file buffer in Unicode mode. > Allow only ASCII characters as input in ASCII mode. > > When saving a file in ASCII mode replace non-ASCII characters by a question > mark ('?'). > > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > --- > Resent due to a typo in Limings email-address. > --- (1) Please run "BaseTools/Scripts/SetupGit.py" in your edk2 clone. (2) This patch was lost because the ShellPkg maintainers were not CC'd. I suggest resending the patch, with the Content-Transfer-Encoding fixed (8bit or base64, per (1)), and with the following folks CC'd (per (2)): Ray Ni <ray.ni@intel.com> Zhichao Gao <zhichao.gao@intel.com> Thanks Laszlo > .../Edit/FileBuffer.c | 21 +++++++++++++++---- > 1 file changed, 17 insertions(+), 4 deletions(-) > > diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c > index fd324cc4a8..12235e4e4b 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c > @@ -1360,6 +1360,8 @@ GetNewLine ( > /** > > Change a Unicode string to an ASCII string. > > > > + Non-ASCII characters are replaced by '?'. > > + > > @param[in] UStr The Unicode string. > > @param[in] Length The maximum size of AStr. > > @param[out] AStr ASCII string to pass out. > > @@ -1378,8 +1380,12 @@ UnicodeToAscii ( > // > > // just buffer copy, not character copy > > // > > - for (Index = 0; Index < Length; Index++) { > > - *AStr++ = (CHAR8) *UStr++; > > + for (Index = 0; Index < Length; Index++, UStr++) { > > + if (*UStr < 0x80) { > > + *AStr++ = (CHAR8) *UStr; > > + } else { > > + *AStr++ = '?'; > > + } > > } > > > > return Index; > > @@ -2154,9 +2160,16 @@ FileBufferDoCharInput ( > > > default: > > // > > - // DEAL WITH ASCII CHAR, filter out thing like ctrl+f > > + // Do not add Unicode control characters to the file buffer: > > + // > > + // * U+0000-U+001f (C0 controls) > > + // * U+007f (DEL) > > + // * U+0080-U+009f (C1 controls) > > + // > > + // Do not add non-ASCII characters in ASCII mode. > > // > > - if (Char > 127 || Char < 32) { > > + if (Char < 0x20 || (Char >= 0x7f && > > + (Char <= 0x9f || FileBuffer.FileType == FileTypeAscii))) { > > Status = StatusBarSetStatusString (L"Unknown Command"); > > } else { > > Status = FileBufferAddChar (Char); > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#66880): https://edk2.groups.io/g/devel/message/66880 Mute This Topic: https://groups.io/mt/61872994/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.