Repository navigation
Modernize the fork for Ruby 3.4+ and fix parser and render crashes - #6
Conversation
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.
There was a problem hiding this comment.
🔵 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.
21aeaaf to
07710b0
Compare
@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 |

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 asetup-rubyrelease 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. Locallybundle exec rspecloaded 0 examples, because the lockfile had noarm64-darwinplatform.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
TypeErrorinas_html.structured_text_heading.jsonhas 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
nilinblocks, soas_htmlandas_textraised.TextandSelectraised on a nil value, andEmbedraised 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.iowithlive: true, andspec_helperexcludes them unlessLIVEis set. I rewrotepredicates_specto parse the bundledapi.jsonmock. 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 raisesPrismicWSAuthErrorand the fallbacks inPrismic.oauth_initiate_urlandPrismic.oauth_check_token.Dead tooling. I deleted
.travis.yml, the OSSAR workflow, the generateddocs/tree (83 files) with its.yardopts, the gulp and npm files, and the Travis badges and Yard note inREADME.mdandCONTRIBUTING.md. The hand-writtendocs-usage/stays.Accessor cleanup.
WebLink,FileLinkandImageLinkdeclared aurlreader and then redefined it, andSearchFormdid the same withref. Each now declares only the writer.SearchForm#qused to defineserializeinside its own body on every call. That logic now lives in a privateserialize_predicate_value. Behaviour is unchanged.Ruby 3.4 and CI.
ruby.ymlruns onmainagainst Ruby 3.4 and 4.0, withactions/checkout@v7andsetup-rubypinned to the v1.344.0 SHA. The gemspec requires Ruby>= 3.4, dropsrspec-core, and packages onlylib/,LICENSE.mdandREADME.md.Prismic.apichecks the URL against a precompiledPrismic::URL_PATTERNbuilt fromURI::RFC2396_PARSER, becauseURI.regexpis obsolete on 3.4. The lockfile drops the java andx86_64-darwin-19platforms and addsarm64-darwin.Nil-tolerant rendering.
Text#as_html,Select#as_htmlandEmbed#as_htmlcallto_sbefore escaping, so a nil value renders an empty string.Parser robustness. In
JsonParser, document links, groups, slices anddocument_parserall go through a new privatefragments_parser. It relies onfragment_parser, which now returns nil for an unknown type, and drops nil results. The unknown-type warning still prints once per type.date_parserandtimestamp_parserreturn nil for an empty value, sofragments_parserleaves the field out of the document.structured_text_parserdrops unknown block types with one warning per type, which replaces the oldputs.StructuredText spans.
Block::Text#as_htmlskips spans that start past the end of the text, and the walk stops slicing at the end of the text.prepare_spansno 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, soabcdefwith 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.