Skip to content

Commit

Permalink
Refactor to a regex-based algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Nov 25, 2023
1 parent cd4bd94 commit b780189
Show file tree
Hide file tree
Showing 53 changed files with 14,248 additions and 13,436 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ RSpec/MultipleExpectations:

RSpec/NestedGroups:
Enabled: false

RSpec/FilePath:
Exclude:
- spec/uri/idna/validation/contexto_spec.rb
- spec/uri/idna/validation/contextj_spec.rb
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning].

## [Unreleased]

### Changed

- Internal implementation moved to regex-based algorithm to improve performance. ([@skryukov])

## [0.2.1] - 2023-11-15

### Changed
Expand Down
18 changes: 12 additions & 6 deletions lib/uri/idna/base_processing.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# frozen_string_literal: true

require_relative "validation/label"
require_relative "validation/codepoint"
require_relative "validation/bidi"

module URI
module IDNA
class BaseProcessing
class << self
def default_options
@default_options ||= options_class.new
end

def options_class
raise NotImplementedError, "Implement #options_class method"
end
end

def initialize(domain_name, **options)
@domain_name = domain_name
@options = options_class.new(**options)
@options = options.any? ? self.class.options_class.new(**options) : self.class.default_options
end

private

attr_reader :domain_name, :options

def options_class
raise NotImplementedError, "Implement #options_class method"
end

def punycode_decode(label)
raise Error, "Label contains non-ASCII code point" unless label.ascii_only?
raise Error, "A-label must not end with a hyphen" if label[-1] == "-"

code = label[ACE_PREFIX.length..]
raise Error, "Malformed A-label, no Punycode eligible content found" if code.empty?
Expand Down
Loading

0 comments on commit b780189

Please sign in to comment.