Handle null or empty text fragment

add code and test cases for null and empty string fragments.