Core simplification, README/security overhaul, Dockerfile + coverage badge CI#3
Open
AlexandreCamillo wants to merge 3 commits into
Open
Conversation
- Replace `String#blank?` (ActiveSupport, dev-only) with stdlib in
SvgDimensions to fix a latent NoMethodError on SVGs without a viewBox.
- Switch raster pixel loops from `Array<Integer>` (`String#bytes`) to
binary `String` + `String#getbyte` to avoid per-call allocations in
BackgroundDetector and PixelAnalyzer.
- Replace Tempfile round-trips with `Vips::Image.new_from_buffer` for
SVG and raster bytes; remove the duplicate vips decode in
`Style.handle_image_path` by surfacing `source_width`/`source_height`
through FeatureMeasurer.
- Extract align-mode constants into VisualCenterTransform and centralize
the visual-center? helper; collapse the four-line scaled-feature
mutation into a hash-driven loop.
- Use `Comparable#clamp` in place of nested `[[v, hi].min, lo].max`,
convert the `img.bands` if/elsif into a `case/when` (preserving the
no-op for `bands == 0`), and use `max_by` for the bucket argmax in
BackgroundDetector.
- Validate inputs in `LogoSoup.style`: warn on unknown option keys,
raise `ArgumentError` for non-String/non-IO `image_bytes`, and
safely transcode SVG bytes via `encode("UTF-8", invalid: :replace,
undef: :replace)` instead of bare `force_encoding`.
- Declare `Css.style_string(**styles)` to match how it's called.
- Tidy `script/coverage_diff.rb` indentation and dedupe nil-init block.
- Bump `.rubocop.yml` TargetRubyVersion 2.7 -> 3.1 (aligns with the
gemspec's `required_ruby_version >= 3.1`).
- Relax dev-dep upper bounds in the gemspec: drop `minitest < 5.26`,
loosen `activesupport < 7.1` -> `< 8` to avoid future bundle-update
breakage.
- Add regression specs for the new ArgumentError and warn-on-unknown
option behaviors.
- README rewritten with TOC and dedicated sections for inputs, options reference, output, recipes (ERB / Rails helper / Phlex / caching), how-it-works (SVG and raster pipelines, sizing and visual-center math), performance, error handling, and development. Inspired by searchkick's README depth. - Add a prominent "Security - trusted inputs only" section at the top: LogoSoup does not enforce size caps, strict MIME matching, or path validation on inputs, and is explicitly NOT intended for end-user uploads or any untrusted source. Document recommended usage (bundled assets, allowlisted internal sources) and the concrete attack vectors (decompression bombs, SVG payloads, path traversal). - Update Development section with Docker workflow (build / test / shell / rake) and a project-layout tree. - CHANGELOG: fill in 0.1.1, 0.1.2, 0.1.3 entries from git history and document the current Unreleased work (Added / Changed / Fixed), including the security notice, Docker image, input validation, encoding safety, internal refactors, and rubocop alignment.
- Add a Dockerfile (Ruby 3.3-slim + libvips + librsvg) so contributors can run the full check suite without installing system dependencies. Gems are baked into the image at build time via BUNDLE_PATH outside /app, so a bind-mounted working tree at runtime keeps gem lookup working without re-running bundle install. - Extend `Coverage Main` workflow to run on every push to main (not just workflow_dispatch). After SimpleCov writes `coverage/.last_run.json`, generate a shields.io endpoint JSON reflecting the line-coverage percentage and color-coded by bucket (>=90 brightgreen, >=75 green, >=60 yellow, >=40 orange, else red). - Publish the JSON to an orphan `badges` branch via native git (no third-party action), so the README badge URL points at shields.io/endpoint with the JSON hosted in the repo itself. No external coverage service or signup required.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three independent improvements landed together for review:
567005a)f80fdcd)7c6580d)Core (567005a)
NoMethodErroron SVGs without aviewBox(drop dev-onlyString#blank?).Vips::Image.new_from_bufferfor SVG and raster bytes. Remove the duplicate vips decode inStyle.handle_image_pathby surfacing source dimensions throughFeatureMeasurer.Array<Integer>(String#bytes) to binaryString+String#getbyteto avoid per-call allocations inBackgroundDetector/PixelAnalyzer.LogoSoup.styleinputs: warn on unknown option keys, raiseArgumentErrorfor non-String/non-IOimage_bytes, and transcode SVG bytes safely (encode("UTF-8", invalid: :replace, undef: :replace)) instead of a bareforce_encoding.VisualCenterTransform,Comparable#clampinstead of nestedmin/max,case/whenforimg.bands,max_byfor bucket argmax,Css.style_string(**styles)to match the call site..rubocop.ymlTargetRubyVersionto 3.1 to match the gemspec; relax dev-dep upper bounds (minitest,activesupport).ArgumentErrorand warn-on-unknown-option behaviors.Docs (f80fdcd)
0.1.1,0.1.2,0.1.3from git history, and the current Unreleased work documented (Added / Changed / Fixed).Build/CI (7c6580d)
Dockerfile(Ruby 3.3-slim + libvips + librsvg) so contributors can run the full check suite without installing system deps. Gems are baked into the image viaBUNDLE_PATHoutside/app, so a bind-mounted working tree at runtime keeps gem lookup working without re-runningbundle install.Coverage Mainworkflow to run on every push tomain. After SimpleCov writescoverage/.last_run.json, generate a shields.io endpoint JSON reflecting line-coverage percentage, color-coded by bucket (>=90brightgreen,>=75green,>=60yellow,>=40orange, else red).badgesbranch via native git (no third-party action). README badge URL points atshields.io/endpointwith the JSON hosted in the repo itself — no external coverage service required.Test plan
bundle exec rake(RSpec + Rubocop) passes against the diff.docker build -t logosoup .succeeds;docker run --rm -v "$PWD":/app logosoup rakeruns the suite in-container.mainwrites the badge JSON tobadgesbranch and the README badge resolves.ArgumentError/warnbehavior against existing callers (only IO/Stringimage_bytes, valid option keys).