Skip to content
Snippets Groups Projects
Commit 97b2abeb authored by A. Unique TensorFlower's avatar A. Unique TensorFlower Committed by TensorFlower Gardener
Browse files

PR #54503: Add appropriate encoding check for `tf.compat.as_bytes`/`as_text`

Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/54503



This PR tries to address the issue raised in #54413 where
there were no encoding check for tf.compat.as_bytes/as_text.
As a result, invalid encoding input will silently
return incorrect result, e.g.:
```
bytes_or_text = "hello"
t1 = tf.compat.as_text(bytes_or_text, encoding="valid")
print(t1) # hello
```

This PR looks up python encoding to make sure it is valid.

This PR fixes #54413.

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
Copybara import of the project:

--
8e3b32d3

 by Yong Tang <yong.tang.github@outlook.com>:

Add appropriate encoding check for tf.compat.as_bytes/as_text

This PR tries to address the issue raised in 54413 where
there were no encoding check for tf.compat.as_bytes/as_text.
As a result, invalid encoding input will silently
return incorrect result, e.g.:
```
bytes_or_text = "hello"
t1 = tf.compat.as_text(bytes_or_text, encoding="valid")
print(t1) # hello
```

This PR looks up python encoding to make sure it is valid.

This PR fixes 54413.

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>

--
6099ca6e

 by Yong Tang <yong.tang.github@outlook.com>:

Add test case for tf.compat.as_bytes/as_text

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/tensorflow/pull/54503 from yongtang:54413-tf.compat.as_bytes-encoding 6099ca6e
PiperOrigin-RevId: 431515245
parent f486229f
No related merge requests found
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment