From e105ca6fb52abee1b9fe1df14e31633f65aeb4c3 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Wed, 28 Jan 2026 11:48:38 +0000 Subject: [PATCH] Remove zero-padding from account slug This shortens URLs in the self-hosted case, where external account ID is typically a small number. --- config/initializers/tenanting/account_slug.rb | 5 ++--- test/middleware/account_slug_extractor_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/initializers/tenanting/account_slug.rb b/config/initializers/tenanting/account_slug.rb index 9d6d83ca73..a79f1f5bf3 100644 --- a/config/initializers/tenanting/account_slug.rb +++ b/config/initializers/tenanting/account_slug.rb @@ -1,6 +1,5 @@ module AccountSlug - PATTERN = /(\d{7,})/ - FORMAT = "%07d" + PATTERN = /(\d+)/ PATH_INFO_MATCH = /\A(\/#{AccountSlug::PATTERN})/ class Extractor @@ -40,7 +39,7 @@ def call(env) end def self.decode(slug) slug.to_i end - def self.encode(id) FORMAT % id end + def self.encode(id) id.to_s end end Rails.application.config.middleware.insert_after Rack::TempfileReaper, AccountSlug::Extractor diff --git a/test/middleware/account_slug_extractor_test.rb b/test/middleware/account_slug_extractor_test.rb index 79a1c6ab98..eb77eb924f 100644 --- a/test/middleware/account_slug_extractor_test.rb +++ b/test/middleware/account_slug_extractor_test.rb @@ -44,6 +44,15 @@ class AccountSlugExtractorTest < ActiveSupport::TestCase assert_nil captured.fetch(:current_account) end + test "encodes account IDs without zero-padding" do + assert_equal "1", AccountSlug.encode(1) + end + + test "decodes both padded and non-padded slugs" do + assert_equal 123, AccountSlug.decode("123") + assert_equal 123, AccountSlug.decode("0000123") + end + private def call_with_env(path, extra_env = {}) captured = {}