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: bad ruler substitution #23

Closed
wants to merge 1 commit into from
Closed

fix: bad ruler substitution #23

wants to merge 1 commit into from

Conversation

N-R-K
Copy link
Contributor

@N-R-K N-R-K commented Jun 20, 2022

Closes: #22


Some before and after:

$ printf "- - -\ntest\n- - -\n" | ./smu-1.5             
<hr />
test
<hr />
$ printf "- - -\ntest\n- - -\n" | ./smu-master 
<hr />

test
<hr />
-
$ printf "- - -\ntest\n- - -\n" | ./smu-fixed 
<hr />
test
<hr />

Note that certain cases, for example - - - without any blank lines before, are still kinda broken:

$ printf "- - -\n\ntest\n- - -\n" | ./smu-1.5
<hr />

test
<hr />
$ printf "- - -\n\ntest\n- - -\n" | ./smu-master
<hr />
<p>test
<hr />
-</p>
$ printf "- - -\n\ntest\n- - -\n" | ./smu-fixed
<hr />
<p>test
<hr />
</p>

Reverting 7228740 is probably a viable fix as well.

@N-R-K
Copy link
Contributor Author

N-R-K commented Jun 25, 2022

@karlb giving a ping, since you were the author of 7228740 and the issue persists on your fork as well.

@karlb
Copy link
Contributor

karlb commented Jun 26, 2022

Thanks, I can reproduce the problem. However, I think the real source of the problem is
https://github.com/Gottox/smu/blob/master/smu.c#L195-L196
where we consume one character without increasing the number of consumed characters returned by dolineprefix.

The following quick hack fixes the problem without breaking any of my tests:

--- a/smu.c
+++ b/smu.c
@@ -226,12 +226,14 @@ dolineprefix(const char *begin, const char *end, int newblock) {
        unsigned int i, j, l;
        char *buffer;
        const char *p;
+       int foo = 0;
 
        if (newblock)
                p = begin;
-       else if (*begin == '\n')
+       else if (*begin == '\n') {
                p = begin + 1;
-       else
+               foo = 1;
+       } else
                return 0;
        for (i = 0; i < LENGTH(lineprefix); i++) {
                l = strlen(lineprefix[i].search);
@@ -244,7 +246,7 @@ dolineprefix(const char *begin, const char *end, int newblock) {
                fputs(lineprefix[i].before, stdout);
                if (lineprefix[i].search[l-1] == '\n') {
                        fputc('\n', stdout);
-                       return l - 1;
+                       return l - 1 + foo;
                }
                if (!(buffer = malloc(BUFSIZ)))
                        eprint("Malloc failed.");

@N-R-K
Copy link
Contributor Author

N-R-K commented Jun 26, 2022

Your proposed patch works in my test scenarios as well. Note that the following case is still sorta broken, but I think that's probably a separate issue:

$ printf "- - -\n\ntest\n- - -\n" | ./smu-1.5
<hr />

test
<hr />
$ printf "- - -\n\ntest\n- - -\n" | ./smu-karlb-patch
<hr />
<p>test
<hr />
</p>

@N-R-K N-R-K closed this Jun 26, 2022
karlb added a commit to karlb/smu that referenced this pull request Jun 26, 2022
@karlb karlb mentioned this pull request Jun 26, 2022
karlb added a commit to karlb/smu that referenced this pull request Jul 17, 2022
@N-R-K N-R-K deleted the hr_fix branch November 1, 2022 18:34
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.

Bad horizontal break substitution in Master branch
2 participants