Skip to content

Commit

Permalink
8303026: [TextField] IOOBE on setting text with control characters th…
Browse files Browse the repository at this point in the history
…at replaces existing text

Reviewed-by: angorya, arapte
  • Loading branch information
Jose Pereda committed Mar 2, 2023
1 parent 00f1aca commit 9df6039
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -181,6 +181,13 @@ private void updateSelectedText() {
} else {
int start = sel.getStart();
int end = sel.getEnd();
int length = txt.length();
if (end > start + length) {
end = length;
}
if (start > length - 1) {
start = end = 0;
}
selectedText.set(txt.substring(start, end));
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -543,6 +543,13 @@ public Integer fromString(String value) {
assertEquals("200", txtField.getText());
}

@Test public void stripInvalidCharacters() {
txtField.setText("abcdefghijklm");
char[] c = new char[]{0x7F, 0xA, 0x9, 0x00, 0x05, 0x10, 0x19};
txtField.setText(String.valueOf(c));
assertEquals("", txtField.getText());
}

private Change upperCase(Change change) {
change.setText(change.getText().toUpperCase());
return change;
Expand Down

0 comments on commit 9df6039

Please sign in to comment.