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:Yong 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:
Yong 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:
Yong 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
Showing
- tensorflow/core/function/BUILD 1 addition, 0 deletionstensorflow/core/function/BUILD
- tensorflow/core/kernels/shape_ops.cc 15 additions, 16 deletionstensorflow/core/kernels/shape_ops.cc
- tensorflow/lite/delegates/gpu/BUILD 2 additions, 1 deletiontensorflow/lite/delegates/gpu/BUILD
- tensorflow/lite/delegates/gpu/delegate.cc 41 additions, 11 deletionstensorflow/lite/delegates/gpu/delegate.cc
- tensorflow/lite/kernels/reduce.cc 11 additions, 2 deletionstensorflow/lite/kernels/reduce.cc
- tensorflow/python/util/BUILD 11 additions, 0 deletionstensorflow/python/util/BUILD
- tensorflow/python/util/compat.py 5 additions, 0 deletionstensorflow/python/util/compat.py
- tensorflow/python/util/compat_test.py 36 additions, 0 deletionstensorflow/python/util/compat_test.py
Please register or sign in to comment