Skip to content

Instantly share code, notes, and snippets.

@robfletcher
Created August 31, 2012 12:03
Show Gist options
  • Save robfletcher/3551913 to your computer and use it in GitHub Desktop.
Save robfletcher/3551913 to your computer and use it in GitHub Desktop.
Demonstrates problem with reading back yaml containing corrupted UTF-8 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')
}
}
@robfletcher
Copy link
Author

Exception occurs on line 29 when assumedCharset is "ISO-8859-1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment