Class: Net::LDAP::FilterParser
- Inherits:
-
Object
- Object
- Net::LDAP::FilterParser
- Defined in:
- lib/net/ldap/filter.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
Instance Method Summary collapse
-
#initialize(str) ⇒ FilterParser
constructor
A new instance of FilterParser.
- #parse(scanner) ⇒ Object
-
#parse_filter_branch(scanner) ⇒ Object
Added a greatly-augmented filter contributed by Andre Nathan for detecting special characters in values.
- #parse_paren_expression(scanner) ⇒ Object
Constructor Details
#initialize(str) ⇒ FilterParser
Returns a new instance of FilterParser.
410 411 412 413 |
# File 'lib/net/ldap/filter.rb', line 410 def initialize str require 'strscan' @filter = parse( StringScanner.new( str )) or raise Net::LDAP::LdapError.new( "invalid filter syntax" ) end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
408 409 410 |
# File 'lib/net/ldap/filter.rb', line 408 def filter @filter end |
Instance Method Details
#parse(scanner) ⇒ Object
415 416 417 |
# File 'lib/net/ldap/filter.rb', line 415 def parse scanner parse_filter_branch(scanner) or parse_paren_expression(scanner) end |
#parse_filter_branch(scanner) ⇒ Object
Added a greatly-augmented filter contributed by Andre Nathan for detecting special characters in values. (15Aug06) Added blanks to the attribute filter (26Oct06)
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/net/ldap/filter.rb', line 466 def parse_filter_branch scanner scanner.scan(/\s*/) if token = scanner.scan( /[\w\-_]+/ ) scanner.scan(/\s*/) if op = scanner.scan( /\=|\<\=|\<|\>\=|\>|\!\=/ ) scanner.scan(/\s*/) #if value = scanner.scan( /[\w\*\.]+/ ) (ORG) #if value = scanner.scan( /[\w\*\.\+\-@=#\$%&! ]+/ ) (ff suggested by Kouhei Sutou if value = scanner.scan( /(?:[\w\*\.\+\-@=,#\$%&! ]|\\[a-fA-F\d]{2,2})+/ ) case op when "=" Filter.eq( token, value ) when "!=" Filter.ne( token, value ) when "<" Filter.lt( token, value ) when "<=" Filter.le( token, value ) when ">" Filter.gt( token, value ) when ">=" Filter.ge( token, value ) end end end end end |
#parse_paren_expression(scanner) ⇒ Object
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/net/ldap/filter.rb', line 419 def parse_paren_expression scanner if scanner.scan(/\s*\(\s*/) b = if scanner.scan(/\s*\&\s*/) a = nil branches = [] while br = parse_paren_expression(scanner) branches << br end if branches.length >= 2 a = branches.shift while branches.length > 0 a = a & branches.shift end a end elsif scanner.scan(/\s*\|\s*/) # TODO: DRY! a = nil branches = [] while br = parse_paren_expression(scanner) branches << br end if branches.length >= 2 a = branches.shift while branches.length > 0 a = a | branches.shift end a end elsif scanner.scan(/\s*\!\s*/) br = parse_paren_expression(scanner) if br ~ br end else parse_filter_branch( scanner ) end if b and scanner.scan( /\s*\)\s*/ ) b end end end |