Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{device,brand,module}_replacement can refer to non-existent capture groups #66

Closed
jimdigriz opened this issue Jul 7, 2015 · 3 comments

Comments

@jimdigriz
Copy link
Contributor

We found '; *(Google )?(Nexus [Ss](?: 4G)?) Build/' failed as both device_replacement and model_replacement can refer to none existent capture groups (if Google is not present then $2 is not defined).

This probably should be rewritten (untested and off the top of my head) as ; *(Google |)(Nexus [Ss](?: 4G)?) Build/ to avoid this.

Really crudely, looks like someone will need to flip through additionally the following to check at least these are safe, but someone is going to have to come up with a regex to test your regex's...Dawg :) Should help in future as they get updated and added to so problems like this do not crop up again:

$ grep -A3 '([^(?:)][^()]*)?' regexes.yaml | grep -B3 '_replacement.*\$' | grep regex:
  - regex: '(Namoroka|Shiretoko|Minefield)/(\d+)\.(\d+)([ab]\d+[a-z]*)?'
  - regex: 'Android Application[^\-]+ - (Sony) ?(Ericsson)? (.+) \w+ - '
  - regex: '; *(Advent )?(Vega(?:Bean|Comb)?).* Build'
  - regex: '; *(Ainol )?((?:NOVO|[Nn]ovo)[^;/]+) Build'
  - regex: '; *(ALLVIEW[ _]?|Allview[ _]?)?(AX1_Shine|AX2_Frenzy) Build'
  - regex: '; *(CUBE[ _])?([KU][0-9]+ ?GT.*|A5300) Build'
  - regex: '; *(HUAWEI |Huawei-)?([UY][^;/]+) Build/(?:Huawei|HUAWEI)([UY][^\);]+)\)'
  - regex: '; *(MODECOM )?(FreeTab) ?([^;/]+) Build'
  - regex: '; *(A\d+)[ _](Duo)? Build'
  - regex: '; *(NOOK )?(BNRV200|BNRV200A|BNTV250|BNTV250A|BNTV400|BNTV600|LogicPD Zoom2) Build'
  - regex: '; *(SKY[ _])?(IM\-[AT]\d{3}[^;/]+).* Build/'
  - regex: 'Android 4\..*; *(M[12356789]|U[12368]|S[123])\ ?(pro)? Build'
  - regex: '; *(?:Polaroid[ _])?((?:MIDC\d{3,}|PMID\d{2,}|PTAB\d{3,})[^;/]*)(\/[^;/]*)? Build/'
  - regex: '; *(A2|A5|A8|A900)_?(Classic)? Build'
  - regex: '; *(SAMSUNG |Samsung )?((?:Galaxy (?:Note II|S\d)|GT-I9082|GT-I9205|GT-N7\d{3}|SM-N9005)[^;/]*)\/?[^;/]* Build/'
  - regex: '; *(Google )?(Nexus [Ss](?: 4G)?) Build/'
  - regex: '; *(SAMSUNG-)?(GT\-[BINPS]\d{4}[^\/]*)(\/[^ ]*) Build'
  - regex: '; *((?:SCH|SGH|SHV|SHW|SPH|SC|SM)\-[A-Za-z0-9 ]+)(/?[^ ]*)? Build'
  - regex: ' ((?:SCH)\-[A-Za-z0-9 ]+)(/?[^ ]*)? Build'
  - regex: '; *((?:CSL_Spice|Spice|SPICE|CSL)[ _\-]?)?([Mm][Ii])([ _\-])?(\d{3}[^;/]*) Build/'
  #~ - regex: '; *(Sprint)? ?(HTC_?)?(X515E|ATP515CKIT|APA7373KT|PG06100|APC715CKT|APX515CKT|PG86100|EVOV4G|APA9292KT|PC36100) Build'
  - regex: '\b(T-Mobile ?)?(myTouch)[ _]?([34]G)[ _]?([^\/]*) (?:Mozilla|Build)'
@commenthol
Copy link
Contributor

Could need a hint on which parser you encountered the failures. Using uap-ref-impl this does not seam to be an issue.

@jimdigriz
Copy link
Contributor Author

The python user_agent_parser.

As a passing question, in the case of the following regex matching some string (say moo cow):

([^ ]+)( [^ ]+)? ([^ ]+)

What would you say $3 should be?

IIRC both Perl and Python will only define $3 if the second capture matches something, otherwise you get undefined variables flying around.

@jimdigriz
Copy link
Contributor Author

Confusion from mis-reading specification

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants