googlefonts / googlefonts/ufo2ft

BaseOutlineCompiler::importTTX: sfntVersion scrubbing fails if TTX file has CRLF line endings

Open
#294 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
176
Forks
48
PR merge metrics
No merged PRs in 30d

Description

1. Convert `tests\data\TestFont.ufo\data\com.github.fonttools.ttx\CUST.ttx` to CRLF line endings
2. Run `test_importTTX`
```
________________ OutlineOTFCompilerTest.test_importTTX[defcon] ________________

self =
testufo =

def test_importTTX(self, testufo):
compiler = OutlineOTFCompiler(testufo)
otf = compiler.otf = TTFont(sfntVersion="OTTO")
compiler.importTTX()
assert "CUST" in otf
assert otf["CUST"].data == b"\x00\x01\xbe\xef"
> assert otf.sfntVersion == "OTTO"
E AssertionError: assert '\x00\x01\x00\x00' == 'OTTO'
E - ☺
E + OTTO

tests\outlineCompiler_test.py:446: AssertionError
_______________ OutlineOTFCompilerTest.test_importTTX[ufoLib2] ________________

self =
testufo =

def test_importTTX(self, testufo):
compiler = OutlineOTFCompiler(testufo)
otf = compiler.otf = TTFont(sfntVersion="OTTO")
compiler.importTTX()
assert "CUST" in otf
assert otf["CUST"].data == b"\x00\x01\xbe\xef"
> assert otf.sfntVersion == "OTTO"
E AssertionError: assert '\x00\x01\x00\x00' == 'OTTO'
E - ☺
E + OTTO

tests\outlineCompiler_test.py:446: AssertionError
```
I asked in #python and was told that `re.MULTILINE` does not consider `\r\n`. Seeing as this is hack at best, should this maybe be done in fontTools instead, i.e. as a kwarg saying that `sfntVersion` should not be imported? Or make the import function accept a XML object so we can do whatever we want beforehand?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure by converting tests/data/TestFont.ufo/data/com.github.fonttools.ttx/CUST.ttx to CRLF line endings and running test_importTTX in tests/outlineCompiler_test.py. Examine BaseOutlineCompiler::importTTX and the reported sfntVersion assertion; done should preserve the CUST data while keeping sfntVersion equal to "OTTO".

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.