jekyll-l10n 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa08de48acfcf87786537131118794ab409b95e3993cb34ad31af021774beceb
4
- data.tar.gz: c3c0bc5a22a1ce203a7623be5217f8477b9d4b57f39918ca221a10f693bbd053
3
+ metadata.gz: c5a4a4261253d5efb8103b3d8896bff9960249f4d6ed69266c0016729b38da43
4
+ data.tar.gz: 582bb044c024621b3bee6407f0ef6f2c6d3f3de8cbca9df14c2449702aaeb446
5
5
  SHA512:
6
- metadata.gz: 9e96fa4c27060bd4a68993d49f4e4a15a2122517a5739434dad81c57f30e712a144c6e15ce0972412ca09a6ffb2f57e3ed83011dbaeff3d456f232919448efd4
7
- data.tar.gz: 74a6fa21f10fe87de0c8f891f9eedb77d36d0df2d50ccd23a794cc20d3a127c183ad6edd35b6284189beb7d0472928ee0bbea8a075fbdfd1abd016586354dbbc
6
+ metadata.gz: cb0212b0e62d331499629fe94eb3983dbaba9d4414804be1f1846873619935acbecf8f26d405b5c10cdc4400bdd246c23f35697ab67bc58deae24b506280f516
7
+ data.tar.gz: dde77b84bb811f0e08fb3bf4cf613cc8cef18bb39e907c7b0bf53a6c0993e33c399bf8b089cab60cbbe5e597725616aae1575b2c21fc9372c299759430c393ba
@@ -84,11 +84,11 @@ module Jekyll
84
84
  false
85
85
  end
86
86
 
87
- def should_transform_href?(href, locale, _baseurl)
87
+ def should_transform_href?(href, locale, baseurl)
88
88
  return false if invalid_href?(href)
89
89
  return false if external_or_special_link?(href)
90
90
  return false if relative_path?(href)
91
- return false if already_localized?(href, locale)
91
+ return false if already_localized?(href, locale, baseurl)
92
92
 
93
93
  true
94
94
  end
@@ -105,8 +105,14 @@ module Jekyll
105
105
  href.start_with?(".")
106
106
  end
107
107
 
108
- def already_localized?(href, locale)
109
- href.start_with?("/#{locale}/") || locale_prefix?(href)
108
+ def already_localized?(href, locale, baseurl = "")
109
+ # Normalize the path by stripping the baseurl if present
110
+ normalized_path = normalize_path(href, baseurl)
111
+
112
+ # Skip transformation if:
113
+ # 1. Path starts with the target locale: /es/page (prevent /es/es/page duplication)
114
+ # 2. Path contains any locale code: /fr/page (preserve language dropdown links)
115
+ normalized_path.start_with?("/#{locale}/") || locale_prefix?(normalized_path)
110
116
  end
111
117
 
112
118
  def language_dropdown_link?(link)
@@ -114,24 +120,46 @@ module Jekyll
114
120
  link_classes.split.any? { |c| c == "dropdown-item" }
115
121
  end
116
122
 
117
- def locale_prefix?(href)
118
- path_without_leading_slash = href.sub(%r!^/!, "")
119
- return false if path_without_leading_slash.empty?
123
+ def normalize_path(href, baseurl)
124
+ # Strip the baseurl prefix if it's present, to get the actual path we're checking
125
+ return href if baseurl.nil? || baseurl.empty?
126
+
127
+ # SECURITY: Only strip if baseurl is followed by "/" (path component boundary)
128
+ # This prevents "/api" from matching "/api2/page" or "/apiurl/page"
129
+ if href == baseurl
130
+ # Exact match: return root path
131
+ "/"
132
+ elsif href.start_with?("#{baseurl}/")
133
+ # Proper path component: strip the baseurl but preserve leading slash
134
+ # href is "/base/es/page", baseurl is "/base"
135
+ # We want to return "/es/page"
136
+ href[baseurl.length..] # Returns "/es/page"
120
137
 
121
- parts = path_without_leading_slash.split("/")
122
- return false if parts.empty?
138
+ else
139
+ # Not a match: return as-is
140
+ href
141
+ end
142
+ end
123
143
 
124
- first_part = parts.first
125
- first_part.match?(%r!^[a-z]{2}(?:_[A-Z]{2})?$!)
144
+ def locale_prefix?(path)
145
+ # Check if the path contains a locale code
146
+ # After stripping baseurl, this detects: /es/, /fr/, /pt_BR/, /zh-CN/, etc.
147
+ path.match?(%r!/[a-z]{2}(?:[_-][A-Z]{2})?(?:/|$)!)
126
148
  end
127
149
 
128
150
  def add_locale_prefix(href, locale, baseurl)
129
151
  return "/#{locale}#{href}" unless baseurl && !baseurl.empty?
130
152
 
131
- if href.start_with?(baseurl)
132
- relative_path = href[baseurl.length..]
133
- "#{baseurl}/#{locale}#{relative_path}"
153
+ # SECURITY: Only strip if baseurl is followed by "/" (path component boundary)
154
+ if href == baseurl
155
+ # Exact match: add locale after baseurl
156
+ "#{baseurl}/#{locale}"
157
+ elsif href.start_with?("#{baseurl}/")
158
+ # Proper path component: insert locale after baseurl
159
+ relative_path = href[(baseurl.length + 1)..]
160
+ "#{baseurl}/#{locale}/#{relative_path}"
134
161
  else
162
+ # Not a match: add locale before href
135
163
  "#{baseurl}/#{locale}#{href}"
136
164
  end
137
165
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-l10n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ReleaseBot