Skip to content

v2.1.0

Choose a tag to compare

@Halvanhelv Halvanhelv released this 07 Sep 15:13
· 100 commits to main since this release
61b845d

Six bugs found while auditing the library. Each was reproduced against the real library before being fixed, and each has a regression test.

All six are fixes, but DeepLDiff::Request::Error is a new public constant, hence the minor bump.

Fixed

The options hash was consumed, not read. #from and #to called Hash#delete on the caller's hash, so a second call with the same hash lost :from and :to and fell through to language detection. A frozen hash — which is what a hash of settings kept in a constant is — raised FrozenError on the very first call. The request copies the hash now.

The chunker measured three different things against one limit. #next_chunk? added the escaped size of the incoming value to a running total of raw String#size, #update_chunk accumulated the raw size, and #validate_value_size compared the raw size. Since CGI.escape inflates Cyrillic sixfold, a chunk of Russian text ran several times over the limit, and a single value whose request size was five times the limit passed validation. Chunking is the only guard against DeepL's request-size limit, and it did not work for any non-Latin text. Everything is measured escaped now — that is what goes over the wire.

A detected source language never matched the target. #detect_language returns a String while :to is usually a Symbol, so from == to could not fire and the text was paid for and translated into its own language. The two are compared case-insensitively as strings now. The cache key is deliberately left alone so existing cached entries stay valid.

A short API response surfaced two layers away. Missing translations shifted nil into the results, which showed up as NoMethodError: undefined method 'strip' for nil inside Spacing. DeepLDiff::Request::Error is raised at the call site now, before a nil can reach the cache.

Non-string scalars crashed. nil and Integer raised NoMethodError on #empty?, Symbol raised TypeError inside Ox. Such values pass through untouched now. nil keeps collapsing to "" inside a structure, exactly as before.

The count limit was off by one. The check ran after the value was added, so a chunk held count_limit + 1 texts.

Upgrade note

The chunker fix changes how non-Latin text is split: chunks are smaller, so there are more requests for the same number of characters billed. This is the correct behaviour, but if your MAX_CHUNK_SIZE was tuned empirically against Cyrillic, the default of 1700 now means a very different payload than it did.

Full changelog: v2.0.0...v2.1.0