• This repository has been archived on 18/Nov/2022
  • Stars
    star
    1
  • Language
    Ruby
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

README

Bug report

Navigating to a route prefixed with #{Rails.application.config.action_cable.mount_path}- 404s.

I discovered this in a Rails 6 application and confirmed the behavior exists on the latest version. It's possible this is expected and I couldn't find that documentation but the behavior is odd enough that I believe this is a bug.

I tried to provide as much info as possible and have provided a reproduction repo and reproduction instructions below. If I can provide anything else, let me know!

If this is a bug, I would be happy to take a stab at fixing it if someone can give me a nudge in the right direction.

Steps to reproduce

  1. Generate new rails app (rails new test-app && cd test-app) or use the one here.
  2. bin/rails g controller Test index
  3. Add these routes to your config/routes.rb:
    get "/cable-hyphenated-slug", to: "test#index"
    get "/cable_underscored_slug", to: "test#index"
  4. Add the following tests to TestControllerTest
      # Fails
      test "route prefixed with 'cable-' should get index" do
        get cable_hyphenated_slug_path
        assert response.ok?
      end
    
      # Succeeds
      test "route prefixed with 'cable_' should get index" do
        get cable_underscored_slug_path
        assert response.ok?
      end
  5. Run the tests to witness the issue
  6. To view in the browser, start the Rails server with rails s
  7. http://localhost:3000/cable_underscored_slug should render the index template
  8. http://localhost:3000/cable-hypenated-slug will 404

Expected behavior

In the example above, /cable-hypenated-slug should be routed to test#index like /cable_underscored_slug is.

Actual behavior

Navigating to a route that is prefixed with #{Rails.application.config.action_cable.mount_path}- 404s but navigating to a route that is prefixed with #{Rails.application.config.action_cable.mount_path}_ works.

# http://localhost:3000/cable-hypenated-slug -> 404
# http://localhost:3000/cable_underscored_slug -> 200

The same is true regardless of the mount path:

config.action_cable.mount_path = "/dev/cable"

# http://localhost:3000/dev/cable-hyphenated-slug -> 404
# http://localhost:3000/dev/cable_underscored_slug -> 200

According to the logs, it looks like Rails tries to split the path on the first hyphen and then try to GET it as a WebSocket request:

2022-06-29 04:04:44 -0700 HTTP parse error, malformed request: #<Puma::HttpParserError: Invalid HTTP format, parsing fails. Are you trying to open an SSL connection to a non-SSL Puma?>
Started GET "/cable-hyphenated-slug" for ::1 at 2022-06-29 04:04:47 -0700
Started GET "/cable/-hyphenated-slug"[non-WebSocket] for ::1 at 2022-06-29 04:04:47 -0700
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, HTTP_UPGRADE: )
Finished "/cable/-hyphenated-slug"[non-WebSocket] for ::1 at 2022-06-29 04:04:47 -0700
Started GET "/cable-hyphenated-slug" for ::1 at 2022-06-29 04:04:47 -0700
Started GET "/cable/-hyphenated-slug"[non-WebSocket] for ::1 at 2022-06-29 04:04:47 -0700
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, HTTP_UPGRADE: )
Finished "/cable/-hyphenated-slug"[non-WebSocket] for ::1 at 2022-06-29 04:04:47 -0700

The easy solution is to not prefix any routes with cable- but I am working in an app where users can set their own slugs for pages and the only solution I can come up with is add that prefix to a blocklist.

System configuration

Rails version:

  • 7.0.3
  • 6.1.5.1

Ruby version:

  • 2.7.5
  • 2.7.6

More Repositories

1

obsidian-beginner-vault-template

A minimal template for your first Obsidian vault aimed at setting good defaults.
56
star
2

awesome-lucky

A collection of awesome Lucky libraries, tools, frameworks and resources
44
star
3

standardrb-action

StandardRB Action: A GitHub Action to run StandardRB against your code!
Ruby
33
star
4

warp-one-dark-darker

Warp theme based on One Dark Darker
26
star
5

shotgun

Ready to go Rails App with TailwindCSS, ViewComponent, Devise, and more!
Ruby
25
star
6

pruner

CLI tool to delete Git branches
Ruby
20
star
7

bundler-audit-action

Bundler Audit Action
Dockerfile
17
star
8

stimulus_reflex_table_filter

Demo app showing how you can filter a table in a Ruby on Rails app with StimulusReflex
Ruby
17
star
9

awesome-bridgetown

A curated list of awesome things related to Bridgetown
13
star
10

rails-extension-power-pack

An extension pack of my favorite VS Code extensions for Ruby on Rails development.
Ruby
11
star
11

forem_lite

A simple tool to help you get articles from Forem/Dev.to
Ruby
11
star
12

andrewm.codes

My personal website built on Bridgetown
HTML
11
star
13

dishwasher

A CLI tool to help you easily delete forked repositories.
Ruby
10
star
14

awesome-stars

An Awesome List of my Awesome Stars
9
star
15

bridgetown-inline-svg

ARCHIVED migrated to bridgetown-svg-inliner
Ruby
9
star
16

bridgetown-netlify-cms-starter

A template to help you get started with Bridgetown + Netlify CMS
JavaScript
8
star
17

bridgetown-gh-pages-action

ARCHIVED See link below, this action is now longer needed following the release of Bridgetown V1
Shell
7
star
18

andrewmcodes

andrewmcodes public readme
6
star
19

andrewmcodes_gem

My gem card
Ruby
4
star
20

haml-lint-action

A GitHub Action that lints your HAML code with HAML Lint!
Ruby
4
star
21

alfred-themes

My personal Alfred 5 themes
4
star
22

redux-on-rails

I DIDNT WANT THIS BUT YOU MADE ME DO IT
Ruby
3
star
23

.github

Default community health files for @andrewmcodes
3
star
24

bridgetown-torchlight-demo

A demo Bridgetown website that has Torchlight syntax highlighting configured!
JavaScript
3
star
25

dotfiles

My personal dot and settings files
Shell
3
star
26

release-please-demo

Ruby
2
star
27

turbo_debug

Ruby
2
star
28

vercel_ruby

WIP Vercel Serverless Functions written in Ruby
Ruby
2
star
29

.dotfiles-update

A temporary repo where I am rebuilding my dotfiles
Shell
2
star
30

actions

Shared GitHub Actions
Shell
1
star
31

prettier-config

My personal Prettier configuration
JavaScript
1
star
32

bridgetown-gh-pages-demo

Demo of the new gh-pages configuration in Bridgetown v1.0
JavaScript
1
star
33

github-actions

MOVED TO andrewmcodes/actions
1
star
34

vscode-tailwindcss-extension-pack

An extension pack for VSCode of extensions for developing with Tailwind CSS.
1
star
35

remote-ruby-vault

Obsidian vault of Remote Ruby episodes for personal research
JavaScript
1
star
36

bridgetown-esbuild-minifySyntax

Benchmarking usage of minifySyntax with esbuild and Bridgetown
JavaScript
1
star
37

warp-radix

Warp theme based on the Radix color system
1
star
38

advent_of_code

Solutions to Advent of Code
Ruby
1
star