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

fix two bugs #9

Merged
merged 4 commits into from
Aug 12, 2015
Merged

fix two bugs #9

merged 4 commits into from
Aug 12, 2015

Conversation

ronwe
Copy link

@ronwe ronwe commented Aug 10, 2015

fix two bugs;
1: while the log variable in square brackets,like
[$remote_addr] parser will throw Invalid regular expression;
2: when then variable is null ,this whole piece of log will parse to
null

fix two bugs;
1: while the log variable in  square brackets,like
[$remote_addr] parser will throw Invalid regular expression;
2: when then variable is null ,this whole piece of log will parse to
null
@@ -19,7 +20,7 @@ var Parser = module.exports = function (format) {
this.directives[match[1]] = i++;
if (match[2]) {
boundary = this.escape(match[2]);
regex = '([^' + boundary + ']+)' + boundary;
regex = '([^' + boundary + ']+)?' + boundary;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regex = '([^' + boundary + ']*?)' + boundary; would be better here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That ? in *? look like not necessary, I change regex = '([^' + boundary + ']+)?' to regex = '([^' + boundary + ']*)'

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The *? is not necessary, but it's slightly more efficient than a plain * because it instructs the regex engine to match characters lazily.

for better perfermance
@chriso
Copy link
Owner

chriso commented Aug 11, 2015

Can you provide an example as to when the variable will be null? It was my understanding that nginx outputs - when a variable is empty.

@ronwe
Copy link
Author

ronwe commented Aug 12, 2015

log_format main '[$seashell]';
$seashell is generated by nginx plugin (http://nginx.org/en/docs/http/ngx_http_userid_module.html), it will print [] not [-] in my case

weiweirong added 2 commits August 12, 2015 10:15
replace [] into [-] while parse line
should fix parser for all case
chriso added a commit that referenced this pull request Aug 12, 2015
@chriso chriso merged commit b10d62f into chriso:master Aug 12, 2015
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.

2 participants