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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Huawei telnet ReadException: Unable to successfully split output based on pattern #2935

Merged
merged 1 commit into from Sep 16, 2022

Conversation

TimGa
Copy link
Contributor

@TimGa TimGa commented Sep 7, 2022

This PR fixes #2711

Root cause:

Unexpected nested group in regex pattern "combined_pattern".
For details please see: #2711 (comment).

Solution:

Change password_change_prompt regex group to non-capturing group. This change avoids nested group in combined_pattern, that solves the root cause. Actually nested group still presents in combined_pattern, but since this group is a non-capturing group, this solves the issue.

Side effects (not detected):

  • Below in code, password_change_prompt used in re.search(password_change_prompt, output) statement. I've tested that changing group to non-capturing group do not affect the re.search statement.
  • Suppose password_change_prompt will need to be passed inside the read_until_pattern method in future. In this case it also will not be a problem, because non-capturing group will be wrapped with parentheses which will change non-capturing group back to regular group, see line pattern = f"({pattern})":
                # The string matched by pattern must be retained in the output string.
                # re.split will do this if capturing parenthesis are used.
                if len(results) == 2:
                    # no capturing parenthesis, convert and try again.
                    pattern = f"({pattern})"
                    results = re.split(pattern, output, maxsplit=1, flags=re_flags)
  • I've tested changes on about 1000 different huawei devices - it works good.

P.S. @ktbyers thank you for non-capturing group idea 馃憤

Incorrect nested groups in regex pattern "combined_pattern".
For details please see: ktbyers#2711 (comment)
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

Successfully merging this pull request may close these issues.

Huawei special_login_handler is not logging in successfully
2 participants