Skip to content

Commit

Permalink
Merge pull request #263 from yohamta/develop
Browse files Browse the repository at this point in the history
fix specialchar parsing issue
  • Loading branch information
yottahmd authored Aug 15, 2022
2 parents 8d56890 + bfad9de commit 6b60624
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 27 deletions.
6 changes: 0 additions & 6 deletions admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Antonio:wght@100;400&family=Noto+Sans+JP:wght@400;700&family=Roboto:wght@400;700&family=Work+Sans:wght@800&display=swap"
rel="stylesheet"
/>
<title>dagu Admin Web</title>
<script>
function getConfig() {
Expand Down
6 changes: 3 additions & 3 deletions admin/src/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ const Drawer = styled(MuiDrawer, {
const mdTheme = createTheme({
typography: {
fontFamily:
"'SF Pro Display','SF Compact Display',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol'",
"'SF Pro Display','SF Compact Display',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol'",
},
palette: {
primary: {
main: '#6149d8',
main: '#485fc7',
}
},
});
Expand All @@ -87,7 +87,7 @@ function Content({ title, navbarColor, children }: DashboardContentProps) {
};
const [scrolled, setScrolled] = React.useState(false);
const containerRef = React.useRef<HTMLDivElement>(null);
const gradientColor = navbarColor || '#6149d8';
const gradientColor = navbarColor || '#485fc7';

return (
<ThemeProvider theme={mdTheme}>
Expand Down
2 changes: 1 addition & 1 deletion admin/src/components/atoms/BorderedBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function BorderedBox({
<Box
sx={{
border: 1,
borderColor: '#6149d8',
borderColor: '#485fc7',
borderRadius: '6px',
...sx,
}}
Expand Down
2 changes: 1 addition & 1 deletion admin/src/components/molecules/DAGTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ function DAGTable({ DAGs = [], group = '', refreshFn }: Props) {
</Stack>
<Box
sx={{
border: '1px solid #6149d8',
border: '1px solid #485fc7',
borderRadius: '6px',
mt: 2,
}}
Expand Down
12 changes: 6 additions & 6 deletions admin/src/components/molecules/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ function Graph({
dat.push(
'linkStyle default stroke:#ddeeff,stroke-width:2px,fill:none,color:#404040'
);
dat.push('classDef none fill:#bbbbff,stroke-width:0px,color:#000');
dat.push('classDef running fill:#33ff33,stroke-width:0px,color:#000');
dat.push('classDef error fill:#ee0000,stroke-width:0px,color:#000');
dat.push('classDef cancel fill:#ffbbaa,stroke-width:0px,color:#000');
dat.push('classDef done fill:#00bb00,stroke-width:0px,color:#000');
dat.push('classDef skipped fill:#dfdfdf,stroke-width:0px,color:#000');
dat.push('classDef none fill:white,stroke:lightblue,stroke-width:2px');
dat.push('classDef running fill:white,stroke:lime,stroke-width:2px');
dat.push('classDef error fill:white,stroke:red,stroke-width:2px');
dat.push('classDef cancel fill:white,stroke:pink,stroke-width:2px');
dat.push('classDef done fill:white,stroke:green,stroke-width:2px');
dat.push('classDef skipped fill:white,stroke:gray,stroke-width:2px');
return dat.join('\n');
}, [steps, onClickNode, flowchart]);
return <Mermaid style={mermaidStyle} def={graph} />;
Expand Down
12 changes: 6 additions & 6 deletions admin/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ type statusColorMapping = {
[key: number]: CSSProperties;
};
export const statusColorMapping: statusColorMapping = {
[SchedulerStatus.None]: { backgroundColor: '#bbbbff' },
[SchedulerStatus.Running]: { backgroundColor: '#33ff33' },
[SchedulerStatus.Error]: { backgroundColor: '#ee0000'},
[SchedulerStatus.Cancel]: { backgroundColor: '#ffbbaa' },
[SchedulerStatus.Success]: { backgroundColor: '#00bb00'},
[SchedulerStatus.Skipped_Unused]: { backgroundColor: '#dfdfdf'},
[SchedulerStatus.None]: { backgroundColor: 'lightblue' },
[SchedulerStatus.Running]: { backgroundColor: 'lime' },
[SchedulerStatus.Error]: { backgroundColor: 'red', color: 'white' },
[SchedulerStatus.Cancel]: { backgroundColor: 'pink' },
[SchedulerStatus.Success]: { backgroundColor: 'green', color: 'white' },
[SchedulerStatus.Skipped_Unused]: { backgroundColor: 'gray', color: 'white' },
};

export const nodeStatusColorMapping = {
Expand Down
4 changes: 2 additions & 2 deletions admin/src/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}

a {
color: #6149d8;
color: #485fc7;
cursor: pointer;
text-decoration: none;
}
Expand All @@ -24,7 +24,7 @@ a {
}

.MuiTableRow-root th {
background-color: #6149d8;
background-color: #485fc7;
color: #fff;
font-weight: 600;
}
Expand Down
5 changes: 5 additions & 0 deletions examples/specialchar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
steps:
- name: step1
command: echo s="\t" test
- name: step2
command: echo s=\t test
52 changes: 52 additions & 0 deletions internal/scheduler/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,58 @@ func TestOutputJson(t *testing.T) {
}
}

func TestOutputSpecialchar(t *testing.T) {
for i, test := range []struct {
CmdWithArgs string
Want string
WantArgs int
}{
{
CmdWithArgs: `echo "hello\tworld"`,
Want: `hello\tworld`,
WantArgs: 1,
},
{
CmdWithArgs: `echo hello"\t"world`,
Want: `hello\tworld`,
WantArgs: 1,
},
{
CmdWithArgs: `echo hello\tworld`,
Want: `hello\tworld`,
WantArgs: 1,
},
{
CmdWithArgs: `echo hello\nworld`,
Want: `hello\nworld`,
WantArgs: 1,
},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
n := &Node{
Step: &dag.Step{
CmdWithArgs: test.CmdWithArgs,
Output: "OUTPUT_SPECIALCHAR_TEST",
OutputVariables: &sync.Map{},
},
}
err := n.setup(os.Getenv("HOME"), fmt.Sprintf("test-output-specialchar-%d", i))
require.NoError(t, err)
defer func() {
_ = n.teardown()
}()

runTestNode(t, n)

require.Equal(t, test.WantArgs, len(n.Args))

v, _ := n.OutputVariables.Load("OUTPUT_SPECIALCHAR_TEST")
require.Equal(t, fmt.Sprintf("OUTPUT_SPECIALCHAR_TEST=%s", test.Want), v)
require.Equal(t, test.Want, os.ExpandEnv("$OUTPUT_SPECIALCHAR_TEST"))
})
}
}

func TestRunScript(t *testing.T) {
n := &Node{
Step: &dag.Step{
Expand Down
28 changes: 26 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,42 @@ func SplitCommand(cmd string, parse bool) (program string, args []string) {
program = vals[0]
parser := shellwords.NewParser()
parser.ParseBacktick = parse
args, err := parser.Parse(vals[1])
parser.ParseEnv = false
a := escapeSpecialchars(vals[1])
args, err := parser.Parse(a)
if err != nil {
log.Printf("failed to parse arguments: %s", err)
//if parse shell world error use all substing as args
return program, []string{vals[1]}
}
return program, args
ret := []string{}
for _, v := range args {
ret = append(ret, unescapeSpecialchars(v))
}
return program, ret

}
return vals[0], []string{}
}

func unescapeSpecialchars(str string) string {
repl := strings.NewReplacer(
`\\t`, `\t`,
`\\r`, `\r`,
`\\n`, `\n`,
)
return repl.Replace(str)
}

func escapeSpecialchars(str string) string {
repl := strings.NewReplacer(
`\t`, `\\t`,
`\r`, `\\r`,
`\n`, `\\n`,
)
return repl.Replace(str)
}

// FileExists returns true if file exists.
func FileExists(file string) bool {
_, err := os.Stat(file)
Expand Down

0 comments on commit 6b60624

Please sign in to comment.