Skip to content

Modernize the fork for Ruby 3.4+ and fix parser and render crashes - #6

Merged
filippoliverani merged 9 commits into
mainfrom
filippoliverani/fork-fixes
Nov 25, 2026
Merged

filippoliverani merged 9 commits into
mainfrom
filippoliverani/fork-fixes

Conversation

@filippoliverani

@filippoliverani filippoliverani commented Nov 25, 2026 •

Copy link
Copy Markdown

This PR brings the fork's CI back to green on Ruby 3.4 and 4.0, fixes the parser and render crashes an audit of the fork turned up, removes tooling the fork doesn't use, and bumps the gem to 1.11.0.

CI was broken in several ways. The workflow triggered on master, tested Ruby 3.0 to 3.2 with a setup-ruby release older than Ruby 4.0, and 49 of 319 examples failed because Prismic's public test repositories (a-bool.prismic.io, privaterepository.prismic.io) no longer exist. Locally bundle exec rspec loaded 0 examples, because the lockfile had no arm64-darwin platform.

The audit and its review also confirmed several crashes, most of them on the app's path:

  • A StructuredText span that starts past the end of its text, or two spans that end past it at different positions, raised TypeError in as_html. structured_text_heading.json has exactly this shape (a 162-183 span on a 22-character heading).

  • A text block rendered once could no longer be Marshal.dumped, because the memoized span hashes carried default procs.

  • An empty Date or Timestamp value raised in Time.parse.

  • An unknown fragment type inside a fetched document link, Group, Multiple or Slice raised NoMethodError. Only top-level fields were filtered.

  • An unknown StructuredText block type left a nil in blocks, so as_html and as_text raised.

  • Text and Select raised on a nil value, and Embed raised on a nil type or provider.

  • Overlapping spans that don't nest (em 0-4, strong 2-6) closed the wrong tag. This bug predates the fork.

  • Offline spec suite. I tagged every example that calls micro.prismic.io with live: true, and spec_helper excludes them unless LIVE is set. I rewrote predicates_spec to parse the bundled api.json mock. The private API OAuth examples hit a repository that no longer exists, so I replaced them with three stubbed examples. They cover the 401 path that raises PrismicWSAuthError and the fallbacks in Prismic.oauth_initiate_url and Prismic.oauth_check_token.

  • Dead tooling. I deleted .travis.yml, the OSSAR workflow, the generated docs/ tree (83 files) with its .yardopts, the gulp and npm files, and the Travis badges and Yard note in README.md and CONTRIBUTING.md. The hand-written docs-usage/ stays.

  • Accessor cleanup. WebLink, FileLink and ImageLink declared a url reader and then redefined it, and SearchForm did the same with ref. Each now declares only the writer. SearchForm#q used to define serialize inside its own body on every call. That logic now lives in a private serialize_predicate_value. Behaviour is unchanged.

  • Ruby 3.4 and CI. ruby.yml runs on main against Ruby 3.4 and 4.0, with actions/checkout@v7 and setup-ruby pinned to the v1.344.0 SHA. The gemspec requires Ruby >= 3.4, drops rspec-core, and packages only lib/, LICENSE.md and README.md. Prismic.api checks the URL against a precompiled Prismic::URL_PATTERN built from URI::RFC2396_PARSER, because URI.regexp is obsolete on 3.4. The lockfile drops the java and x86_64-darwin-19 platforms and adds arm64-darwin.

  • Nil-tolerant rendering. Text#as_html, Select#as_html and Embed#as_html call to_s before escaping, so a nil value renders an empty string.

  • Parser robustness. In JsonParser, document links, groups, slices and document_parser all go through a new private fragments_parser. It relies on fragment_parser, which now returns nil for an unknown type, and drops nil results. The unknown-type warning still prints once per type. date_parser and timestamp_parser return nil for an empty value, so fragments_parser leaves the field out of the document. structured_text_parser drops unknown block types with one warning per type, which replaces the old puts.

  • StructuredText spans. Block::Text#as_html skips spans that start past the end of the text, and the walk stops slicing at the end of the text. prepare_spans no longer memoizes or uses default procs. Blocks without spans take a fast path that escapes the text directly. When a span ends inside another one, the walk now closes the outer tags it crosses and reopens them after it, so abcdef with em 0-4 and strong 2-6 renders <em>ab<strong>cd</strong></em><strong>ef</strong>.

  • Version. 1.10.0 to 1.11.0. I picked a minor bump because the Ruby floor moved and empty or unknown fields now drop keys from fragments.

Tags every example that calls micro.prismic.io with `live: true` and
excludes them unless LIVE is set, so `bundle exec rspec` no longer
depends on Prismic's public test repositories being reachable.

The predicates specs now parse the bundled api.json mock instead of
fetching micro.prismic.io and a-bool.prismic.io. The private API OAuth
specs stub the HTTP client with a 401 response that carries the OAuth
endpoints, replacing calls to privaterepository.prismic.io.
The fork runs CI on GitHub Actions and does not publish API docs.
Deletes the Travis config and its README badges, the OSSAR workflow,
the generated docs/ tree with its .yardopts, and the gulp and npm
files with their node_modules ignore entry.
WebLink, FileLink and ImageLink declared an `url` reader and then
redefined it; SearchForm did the same with `ref`. Each now declares
only the writer. SearchForm#q defined `serialize` inside its own body on
every call; the logic moves to a private `serialize_predicate_value`.
Reindents BooleanField. Behavior is unchanged.
Runs the GitHub Actions workflow on main against Ruby 3.4 and 4.0 with
current checkout and setup-ruby actions, and sets the gemspec's
required_ruby_version to match.

Builds the URL check in Prismic.api from URI::RFC2396_PARSER, since
URI.regexp is obsolete on Ruby 3.4. The gem now packages only lib/,
LICENSE.md and README.md instead of every tracked file. Drops the
redundant rspec-core dependency, the yajl fallback in spec_helper, and
the java and x86_64-darwin-19 lockfile platforms in favor of
arm64-darwin.
Text and Select raised on a nil value, and Embed raised on a nil type
or provider, because CGI.escapeHTML requires a String. Each now
converts the value with to_s and renders an empty string.
Only document_parser filtered out fragments of unknown type; document
links, groups, multiples and slices called a nil parser and raised.
All of them now go through fragment_parser, which warns once per
unknown type and returns nil, and the callers drop nil results.

Date and Timestamp fields with an empty value are omitted instead of
raising in Time.parse. Unknown structured text block types are dropped
with a single warning per type instead of a `puts` and a nil block.
A span ending inside another span popped the wrong tag off the stack.
The outer tags it crossed are now closed and reopened after it, so
overlapping spans nest correctly. Spans that start past the end of the
text are ignored, and text slicing stops at the end of the text.

Drops the memoized span hashes, whose default procs made rendered
blocks fail Marshal.dump, and renders blocks without spans as escaped
text directly.
@filippoliverani filippoliverani self-assigned this Nov 25, 2026
@filippoliverani
filippoliverani requested an adaptive review from Copilot November 25, 2026 10:00
@filippoliverani
filippoliverani marked this pull request as ready for review November 25, 2026 10:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Passing the caller’s URI object to the HTTP client allows query-parameter mutation, leaving credentials in the original URI and causing reused requests to send duplicate access tokens.

No open issues 🎉

What changed in this PR

This PR modernizes the Prismic Ruby SDK fork for Ruby 3.4+ and release 1.11.0, improves parser and rendering robustness, and makes the default spec suite independent of live services.

Changes:

  • Updates CI, Ruby requirements, gem packaging, and dependency platforms while removing unused tooling and generated documentation.
  • Handles empty and unknown fields, nil rendering values, and malformed or overlapping StructuredText spans.
  • Adds regression tests, replaces private OAuth integration tests with stubs, and makes live examples opt-in.
File Description
spec/​spec_helper.rb Excludes live examples by default; simplifies JSON loading.
spec/​simple_search_spec.rb Marks search integration examples as live.
spec/​prismic_spec.rb Marks the OAuth URL integration example as live.
spec/​predicates_spec.rb Uses a bundled API fixture instead of live repositories.
spec/​oauth_spec.rb Adds stubbed private OAuth coverage; tags public examples as live.
spec/​micro_spec.rb Marks repository integration examples as live.
spec/​json_parsers_spec.rb Adds unknown-type and empty-date regression coverage.
spec/​fragments_spec.rb Adds rendering and serialization regressions; tags live Group examples.
spec/​cache_spec.rb Marks cache integration examples as live.
README.md Documents offline/live testing and removes obsolete tooling references.
prismic.gemspec Requires Ruby 3.4+ and narrows packaged files and development dependencies.
package.json Removes unused npm tooling.
lib/​prismic/​version.rb Bumps the gem version to 1.11.0.
lib/​prismic/​json_parsers.rb Filters unsupported fragments and blocks; omits empty dates.
lib/​prismic/​fragments/​text.rb Makes HTML rendering tolerate nil values.
lib/​prismic/​fragments/​structured_text.rb Handles span bounds and overlaps; removes memoization and optimizes span-free rendering.
lib/​prismic/​fragments/​select.rb Makes HTML rendering tolerate nil values.
lib/​prismic/​fragments/​link.rb Removes redundant generated URL readers.
lib/​prismic/​fragments/​embed.rb Handles nil embed types and providers.
lib/​prismic/​fragments/​boolean_field.rb Normalizes indentation without changing behavior.
lib/​prismic.rb Modernizes URL validation and cleans up SearchForm helpers.
gulpfile.js Removes unused deployment tasks.
Gemfile.lock Updates the gem version, platforms, and Bundler metadata.
docs/​top-level-namespace.html Removes generated namespace documentation.
docs/​Prismic/​SearchForm/​UnsupportedFormKind.html Removes generated exception documentation.
docs/​Prismic/​SearchForm/​RefNotFoundException.html Removes generated exception documentation.
docs/​Prismic/​SearchForm/​NoRefSetException.html Removes generated exception documentation.
docs/​Prismic/​SearchForm/​FormSearchException.html Removes generated exception documentation.
docs/​Prismic/​SearchForm/​AuthorizationException.html Removes generated exception documentation.
docs/​Prismic/​SearchForm/​AuthenticationException.html Removes generated exception documentation.
docs/​Prismic/​HtmlSerializer.html Removes generated serializer documentation.
docs/​Prismic/​Fragments/​WebLink.html Removes generated fragment documentation.
docs/​Prismic/​Fragments/​Text.html Removes generated fragment documentation.
docs/​Prismic/​Fragments/​StructuredText/​Span/​Strong.html Removes generated span documentation.
docs/​Prismic/​Fragments/​StructuredText/​Span/​Em.html Removes generated span documentation.
docs/​Prismic/​Fragments/​StructuredText/​Block/​Preformatted.html Removes generated block documentation.
docs/​Prismic/​Fragments/​StructuredText/​Block/​Paragraph.html Removes generated block documentation.
docs/​Prismic/​Fragments/​StructuredText/​Block.html Removes generated block documentation.
docs/​Prismic/​Fragments/​Separator.html Removes generated fragment documentation.
docs/​Prismic/​Fragments/​Select.html Removes generated fragment documentation.
docs/​Prismic/​Fragments/​Number.html Removes generated fragment documentation.
docs/​Prismic/​Fragments/​ImageLink.html Removes generated fragment documentation.
docs/​Prismic/​Fragments/​Image/​ViewDoesNotExistException.html Removes generated exception documentation.
docs/​Prismic/​Fragments/​Date.html Removes generated fragment documentation.
docs/​Prismic/​Fragments.html Removes generated fragment namespace documentation.
docs/​Prismic/​Field.html Removes generated field documentation.
docs/​Prismic/​BasicNullCache.html Removes generated cache documentation.
docs/​Prismic/​API/​PrismicWSConnectionError.html Removes generated exception documentation.
docs/​Prismic/​API/​BadPrismicResponseError.html Removes generated exception documentation.
docs/​js/​full_list.js Removes generated documentation navigation scripts.
docs/​js/​app.js Removes generated documentation interface scripts.
docs/​index.html Removes the generated documentation landing page.
docs/​frames.html Removes the generated documentation frame redirect.
docs/​file.README.html Removes the generated README page.
docs/​file_list.html Removes the generated documentation file index.
docs/​css/​full_list.css Removes generated documentation navigation styles.
docs/​css/​common.css Removes the documentation stylesheet placeholder.
CONTRIBUTING.md Removes the obsolete Travis badge.
.yardopts Removes generated documentation configuration.
.travis.yml Removes legacy Travis CI and deployment configuration.
.gitignore Removes the unused Node dependency ignore entry.
.github/​workflows/​ruby.yml Targets main and Ruby 3.4/4.0 with updated actions.
.github/​workflows/​ossar-analysis.yml Removes the unused static-analysis workflow.

Review effort: Balanced (adaptive)

DefaultHTTPClient.get and .post appended the query to the URI object
they received. A caller that passed the same URI more than once sent
the access token again on every call, and the query grew with each
request. Both methods now add the query to a copy and leave the
caller's URI unchanged.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change lacks regression coverage for mixed known/unknown fragments, and the README still advertises Ruby 1.9.3 support despite the new Ruby 3.4 minimum.

1 open issue

Review effort: Balanced (adaptive)

Comment thread prismic.gemspec Resolved
@filippoliverani

filippoliverani commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

The change lacks regression coverage for mixed known/unknown fragments, and the README still advertises Ruby 1.9.3 support despite the new Ruby 3.4 minimum.
1 open issue

* <img alt="Low severity" width="62" height="18" src="https://camo.githubusercontent.com/2e8987a2fc4f02d25f9b6b7e5875dc9332cc93fdc58a140b40910ba3fbc50079/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f7374617469632f696d616765732f69636f6e732f636f70696c6f742d636f64652d7265766965772f6c6f772d76322d6c696768742e706e67"> [Update README Ruby requirement to 3.4 or later](https://github.com/FrameworkComputer/prismic-ruby-kit/pull/6#discussion_r4693992792) · New

@copilot The mutation was already there in DefaultHTTPClient, but this PR made it reachable through Prismic.api, which now accepts a URI object. I fixed it in 5082577: get and post now work on a copy of the URI, and I added a spec that calls each of them twice with the same URI

@filippoliverani
filippoliverani merged commit 60f60bd into main Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants