Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ bool isTextOnly(QByteArray data, const QString& encoding, bool quickTest)
QString text (data);
bool isPrintable = true;
for(QChar character : text) {
if(character.isNonCharacter() || (character.category() == QChar::Other_Control && !character.isSpace())) {
// The ASCII information separators (U+001C to U+001F) are control characters which Qt does not consider
// white space. They are regularly used as field delimiters in text, though, so don't treat them as binary.
const bool isSeparator = character.unicode() >= 0x1C && character.unicode() <= 0x1F;
if(character.isNonCharacter() || (character.category() == QChar::Other_Control && !character.isSpace() && !isSeparator)) {
isPrintable = false;
break;
}
Expand Down
22 changes: 22 additions & 0 deletions src/tests/TestRegex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ void TestRegex::clipboardRows()
QVERIFY(parseClipboard(text) == expected);
}

void TestRegex::isTextOnlyControlCharacters_data()
{
QTest::addColumn<QByteArray>("data");
QTest::addColumn<bool>("expected");

QTest::newRow("plain") << QByteArray("John Mary") << true;
QTest::newRow("whitespace-controls") << QByteArray("a\tb\r\nc") << true;
QTest::newRow("unit-separator") << QByteArray("John\x1f" "Mary") << true;
QTest::newRow("record-separator") << QByteArray("a\x1e" "b") << true;
QTest::newRow("group-and-file-separator") << QByteArray("a\x1d" "b\x1c" "c") << true;
QTest::newRow("nul") << QByteArray("a\0b", 3) << false;
QTest::newRow("bell") << QByteArray("a\x07" "b") << false;
QTest::newRow("escape") << QByteArray("a\x1b" "b") << false;
}

void TestRegex::isTextOnlyControlCharacters()
{
QFETCH(QByteArray, data);
QFETCH(bool, expected);
QCOMPARE(isTextOnly(data), expected);
}

void TestRegex::sqlQueryComments_data()
{
QTest::addColumn<QString>("dirtyQuery");
Expand Down
2 changes: 2 additions & 0 deletions src/tests/TestRegex.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ private slots:
void sqlQueryComments_data();
void clipboardRows();
void clipboardRows_data();
void isTextOnlyControlCharacters();
void isTextOnlyControlCharacters_data();
};

#endif
Loading