All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] docparse: Replace \t with space
@ 2021-01-21 13:00 Petr Vorel
  2021-01-21 13:00 ` [LTP] [PATCH 2/2] testinfo.pl: Optimize imports Petr Vorel
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Petr Vorel @ 2021-01-21 13:00 UTC (permalink / raw)
  To: ltp

to avoid constant failures because tabs are forbidden in JSON.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi,

Currently required for "Convert CAN tests to new LTP API" patchset
https://patchwork.ozlabs.org/project/ltp/patch/20210120143723.26483-5-rpalethorpe@suse.com/
https://patchwork.ozlabs.org/project/ltp/patch/20210120143723.26483-6-rpalethorpe@suse.com/

Kind regards,
Petr

 docparse/data_storage.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/docparse/data_storage.h b/docparse/data_storage.h
index ef420c08f..99c2514b7 100644
--- a/docparse/data_storage.h
+++ b/docparse/data_storage.h
@@ -54,6 +54,7 @@ static inline struct data_node *data_node_string(const char *string)
 {
 	size_t size = sizeof(struct data_node_string) + strlen(string) + 1;
 	struct data_node *node = malloc(size);
+	char *ix = node->string.val;
 
 	if (!node)
 		return NULL;
@@ -61,6 +62,9 @@ static inline struct data_node *data_node_string(const char *string)
 	node->type = DATA_STRING;
 	strcpy(node->string.val, string);
 
+	while ((ix = strchr(ix, '\t')))
+		*ix++ = ' ';
+
 	return node;
 }
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 2/2] testinfo.pl: Optimize imports
  2021-01-21 13:00 [LTP] [PATCH 1/2] docparse: Replace \t with space Petr Vorel
@ 2021-01-21 13:00 ` Petr Vorel
  2021-01-28 14:53   ` Petr Vorel
  2021-01-21 13:05 ` [LTP] [PATCH 1/2] docparse: Replace \t with space Petr Vorel
  2021-01-21 14:47 ` Richard Palethorpe
  2 siblings, 1 reply; 10+ messages in thread
From: Petr Vorel @ 2021-01-21 13:00 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 docparse/testinfo.pl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/docparse/testinfo.pl b/docparse/testinfo.pl
index b636b3c0e..b5ab02bc1 100755
--- a/docparse/testinfo.pl
+++ b/docparse/testinfo.pl
@@ -6,8 +6,7 @@
 use strict;
 use warnings;
 
-use JSON;
-use LWP::Simple;
+use JSON qw(decode_json);
 use Cwd qw(abs_path);
 use File::Basename qw(dirname);
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/2] docparse: Replace \t with space
  2021-01-21 13:00 [LTP] [PATCH 1/2] docparse: Replace \t with space Petr Vorel
  2021-01-21 13:00 ` [LTP] [PATCH 2/2] testinfo.pl: Optimize imports Petr Vorel
@ 2021-01-21 13:05 ` Petr Vorel
  2021-01-21 14:47 ` Richard Palethorpe
  2 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2021-01-21 13:05 UTC (permalink / raw)
  To: ltp

Hi,

...
>  	size_t size = sizeof(struct data_node_string) + strlen(string) + 1;
>  	struct data_node *node = malloc(size);
> +	char *ix = node->string.val;

>  	if (!node)
>  		return NULL;
> @@ -61,6 +62,9 @@ static inline struct data_node *data_node_string(const char *string)
>  	node->type = DATA_STRING;
>  	strcpy(node->string.val, string);

Probably better to comment this:
/* tabs are not allowed in JSON */
> +	while ((ix = strchr(ix, '\t')))
> +		*ix++ = ' ';

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/2] docparse: Replace \t with space
  2021-01-21 13:00 [LTP] [PATCH 1/2] docparse: Replace \t with space Petr Vorel
  2021-01-21 13:00 ` [LTP] [PATCH 2/2] testinfo.pl: Optimize imports Petr Vorel
  2021-01-21 13:05 ` [LTP] [PATCH 1/2] docparse: Replace \t with space Petr Vorel
@ 2021-01-21 14:47 ` Richard Palethorpe
  2021-01-21 14:50   ` Cyril Hrubis
  2 siblings, 1 reply; 10+ messages in thread
From: Richard Palethorpe @ 2021-01-21 14:47 UTC (permalink / raw)
  To: ltp

Hello,

Petr Vorel <pvorel@suse.cz> writes:

> to avoid constant failures because tabs are forbidden in JSON.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Hi,
>
> Currently required for "Convert CAN tests to new LTP API" patchset
> https://patchwork.ozlabs.org/project/ltp/patch/20210120143723.26483-5-rpalethorpe@suse.com/
> https://patchwork.ozlabs.org/project/ltp/patch/20210120143723.26483-6-rpalethorpe@suse.com/
>
> Kind regards,
> Petr
>
>  docparse/data_storage.h | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/docparse/data_storage.h b/docparse/data_storage.h
> index ef420c08f..99c2514b7 100644
> --- a/docparse/data_storage.h
> +++ b/docparse/data_storage.h
> @@ -54,6 +54,7 @@ static inline struct data_node *data_node_string(const char *string)
>  {
>  	size_t size = sizeof(struct data_node_string) + strlen(string) + 1;
>  	struct data_node *node = malloc(size);
> +	char *ix = node->string.val;
>  
>  	if (!node)
>  		return NULL;
> @@ -61,6 +62,9 @@ static inline struct data_node *data_node_string(const char *string)
>  	node->type = DATA_STRING;
>  	strcpy(node->string.val, string);
>  
> +	while ((ix = strchr(ix, '\t')))
> +		*ix++ = ' ';


JQ says "control characters from U+0000 through U+001F must be
escaped". So I expect it is only a matter of time until some other
control character is used.

Perhaps we should escape all control characters into the \uXXXX
hexidecimal form?

http://www.json.org/json-en.html

> +
>  	return node;
>  }


-- 
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/2] docparse: Replace \t with space
  2021-01-21 14:47 ` Richard Palethorpe
@ 2021-01-21 14:50   ` Cyril Hrubis
  2021-01-21 15:43     ` Petr Vorel
  0 siblings, 1 reply; 10+ messages in thread
From: Cyril Hrubis @ 2021-01-21 14:50 UTC (permalink / raw)
  To: ltp

Hi!
> JQ says "control characters from U+0000 through U+001F must be
> escaped". So I expect it is only a matter of time until some other
> control character is used.
> 
> Perhaps we should escape all control characters into the \uXXXX
> hexidecimal form?

Or fail the compilation if we get one of these into the parser?

There is no point in having them in the metadata anyways.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/2] docparse: Replace \t with space
  2021-01-21 14:50   ` Cyril Hrubis
@ 2021-01-21 15:43     ` Petr Vorel
  2021-01-21 15:59       ` Richard Palethorpe
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Vorel @ 2021-01-21 15:43 UTC (permalink / raw)
  To: ltp

Hi,

> > JQ says "control characters from U+0000 through U+001F must be
> > escaped". So I expect it is only a matter of time until some other
> > control character is used.
+1

> > Perhaps we should escape all control characters into the \uXXXX
> > hexidecimal form?

> Or fail the compilation if we get one of these into the parser?
We do fail already, but it's a bit hidden now.
I don't know why build continues for so long.

Also there would have to be striking error message.
But docparser is not mandatory (people might have it disabled), thus mostly it
will be us the maintainers who is going to fix these whitespace issues :(.

> There is no point in having them in the metadata anyways.
That would be solved by replacing some reasonable subset. So far it was the tab
character.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/2] docparse: Replace \t with space
  2021-01-21 15:43     ` Petr Vorel
@ 2021-01-21 15:59       ` Richard Palethorpe
  2021-01-21 16:20         ` Petr Vorel
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Palethorpe @ 2021-01-21 15:59 UTC (permalink / raw)
  To: ltp

Hello,

Petr Vorel <pvorel@suse.cz> writes:

> Hi,
>
>> > JQ says "control characters from U+0000 through U+001F must be
>> > escaped". So I expect it is only a matter of time until some other
>> > control character is used.
> +1
>
>> > Perhaps we should escape all control characters into the \uXXXX
>> > hexidecimal form?
>
>> Or fail the compilation if we get one of these into the parser?
> We do fail already, but it's a bit hidden now.
> I don't know why build continues for so long.
>
> Also there would have to be striking error message.
> But docparser is not mandatory (people might have it disabled), thus mostly it
> will be us the maintainers who is going to fix these whitespace issues :(.
>
>> There is no point in having them in the metadata anyways.
> That would be solved by replacing some reasonable subset. So far it was the tab
> character.
>
> Kind regards,
> Petr

I suppose actually I could just escape the tab in the C string. But as
Petr says, docparse is not mandatory so anything which can pass C
compilation, but fails docparse is likely to create trouble.

It would be possible to force running docparse and doing some validation
on the JSON. As this would not require any more dependencies. In fact it
would be nice to run docparse to produce just the JSON without having to
install asciidoc[tor].

The Makefile doesn't seem to allow this. Although it is quite easy to
compile docparse without it.

-- 
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/2] docparse: Replace \t with space
  2021-01-21 15:59       ` Richard Palethorpe
@ 2021-01-21 16:20         ` Petr Vorel
  2021-01-21 16:28           ` Cyril Hrubis
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Vorel @ 2021-01-21 16:20 UTC (permalink / raw)
  To: ltp

> Hello,

> Petr Vorel <pvorel@suse.cz> writes:

> > Hi,

> >> > JQ says "control characters from U+0000 through U+001F must be
> >> > escaped". So I expect it is only a matter of time until some other
> >> > control character is used.
> > +1

> >> > Perhaps we should escape all control characters into the \uXXXX
> >> > hexidecimal form?

> >> Or fail the compilation if we get one of these into the parser?
> > We do fail already, but it's a bit hidden now.
> > I don't know why build continues for so long.

> > Also there would have to be striking error message.
> > But docparser is not mandatory (people might have it disabled), thus mostly it
> > will be us the maintainers who is going to fix these whitespace issues :(.

> >> There is no point in having them in the metadata anyways.
> > That would be solved by replacing some reasonable subset. So far it was the tab
> > character.

> > Kind regards,
> > Petr

> I suppose actually I could just escape the tab in the C string. But as
"escape the tab in C string" that's what it's being done in this patch.

> Petr says, docparse is not mandatory so anything which can pass C
> compilation, but fails docparse is likely to create trouble.
+1.

> It would be possible to force running docparse and doing some validation
> on the JSON. As this would not require any more dependencies. In fact it
> would be nice to run docparse to produce just the JSON without having to
> install asciidoc[tor].

> The Makefile doesn't seem to allow this. Although it is quite easy to
> compile docparse without it.
That'd be easy to change.

But, there is perl package dependency. If possible I'd allow people to compile
LTP without bothering with CPAN (mainly due these embedded build source distros,
e.g. Buildroot, Yocto).

Generally I'd decouple requirements for C source code content and JSON.
\t in C source will be printed as tab, that's ok.
That's why I changed the formatting in docparse/data_storage.h.
I wonder how many escape strings we want to use. Maybe \n (if that's not already
handled).

I wonder if we can do some string validation in git commit or push hooks.
Although not sure if it's a good idea.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/2] docparse: Replace \t with space
  2021-01-21 16:20         ` Petr Vorel
@ 2021-01-21 16:28           ` Cyril Hrubis
  0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2021-01-21 16:28 UTC (permalink / raw)
  To: ltp

Hi!
> > The Makefile doesn't seem to allow this. Although it is quite easy to
> > compile docparse without it.
> That'd be easy to change.
> 
> But, there is perl package dependency. If possible I'd allow people to compile
> LTP without bothering with CPAN (mainly due these embedded build source distros,
> e.g. Buildroot, Yocto).

I guess that we can easily catch any non-ascii characters in the C
docparse tool, no perl needed.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 2/2] testinfo.pl: Optimize imports
  2021-01-21 13:00 ` [LTP] [PATCH 2/2] testinfo.pl: Optimize imports Petr Vorel
@ 2021-01-28 14:53   ` Petr Vorel
  0 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2021-01-28 14:53 UTC (permalink / raw)
  To: ltp

Hi,

> Signed-off-by: Petr Vorel <pvorel@suse.cz>
Merged this simple one.

Kind regards,
Petr

> ---
>  docparse/testinfo.pl | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

> diff --git a/docparse/testinfo.pl b/docparse/testinfo.pl
> index b636b3c0e..b5ab02bc1 100755
> --- a/docparse/testinfo.pl
> +++ b/docparse/testinfo.pl
> @@ -6,8 +6,7 @@
>  use strict;
>  use warnings;

> -use JSON;
> -use LWP::Simple;
> +use JSON qw(decode_json);
>  use Cwd qw(abs_path);
>  use File::Basename qw(dirname);

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-01-28 14:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 13:00 [LTP] [PATCH 1/2] docparse: Replace \t with space Petr Vorel
2021-01-21 13:00 ` [LTP] [PATCH 2/2] testinfo.pl: Optimize imports Petr Vorel
2021-01-28 14:53   ` Petr Vorel
2021-01-21 13:05 ` [LTP] [PATCH 1/2] docparse: Replace \t with space Petr Vorel
2021-01-21 14:47 ` Richard Palethorpe
2021-01-21 14:50   ` Cyril Hrubis
2021-01-21 15:43     ` Petr Vorel
2021-01-21 15:59       ` Richard Palethorpe
2021-01-21 16:20         ` Petr Vorel
2021-01-21 16:28           ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.