Created
August 31, 2012 12:03
-
-
Save robfletcher/3551913 to your computer and use it in GitHub Desktop.
Demonstrates problem with reading back yaml containing corrupted UTF-8 characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package yaml.encoding | |
import org.yaml.snakeyaml.Yaml | |
import spock.lang.* | |
@Unroll | |
class YamlEncodingSpec extends Specification { | |
Yaml yaml = new Yaml() | |
File file | |
void setup() { | |
file = File.createTempFile('data', '.yaml') | |
} | |
void cleanup() { | |
file.delete() | |
} | |
void 'can read back data encoded as #assumedCharset'() { | |
given: | |
def originalObject = [s: new String(bytes, assumedCharset)] | |
file.withWriter { writer -> | |
yaml.dump(originalObject, writer) | |
} | |
when: | |
def loadedObject = file.withInputStream { stream -> | |
yaml.load(stream) | |
} | |
then: | |
loadedObject.s == originalObject.s | |
where: | |
assumedCharset << ['UTF-8', 'ISO-8859-1'] | |
bytes = 'dt:before{content:"\u2666 "}'.getBytes('UTF-8') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exception occurs on line 29 when
assumedCharset
is"ISO-8859-1"