mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Fixed potential npe
This commit is contained in:
		
							parent
							
								
									4eaadf98d0
								
							
						
					
					
						commit
						e5948c4f16
					
				| @ -617,6 +617,27 @@ pointer: *value-pointer` | ||||
| 	test.AssertResult(t, expectedOutput, result.Output) | ||||
| } | ||||
| 
 | ||||
| func TestReadMergeAnchorsExplodeMissingCmd(t *testing.T) { | ||||
| 	content := `a: | ||||
|   <<: &anchor | ||||
|   c: d | ||||
|   e: f | ||||
| ` | ||||
| 	filename := test.WriteTempYamlFile(content) | ||||
| 	defer test.RemoveTempYamlFile(filename) | ||||
| 
 | ||||
| 	cmd := getRootCommand() | ||||
| 	result := test.RunCmd(cmd, fmt.Sprintf("read -X %s", filename)) | ||||
| 	if result.Error != nil { | ||||
| 		t.Error(result.Error) | ||||
| 	} | ||||
| 	expectedOutput := `a: | ||||
|   c: d | ||||
|   e: f | ||||
| ` | ||||
| 	test.AssertResult(t, expectedOutput, result.Output) | ||||
| } | ||||
| 
 | ||||
| func TestReadMergeAnchorsExplodeKeyCmd(t *testing.T) { | ||||
| 	content := `name: &nameField Mike | ||||
| *nameField: Great Guy` | ||||
|  | ||||
| @ -163,6 +163,9 @@ func setIfNotThere(node *yaml.Node, key string, value *yaml.Node) { | ||||
| } | ||||
| 
 | ||||
| func applyAlias(node *yaml.Node, alias *yaml.Node) { | ||||
| 	if alias == nil { | ||||
| 		return | ||||
| 	} | ||||
| 	for index := 0; index < len(alias.Content); index = index + 2 { | ||||
| 		keyNode := alias.Content[index] | ||||
| 		log.Debugf("applying alias key %v", keyNode.Value) | ||||
| @ -185,12 +188,14 @@ func explodeNode(node *yaml.Node) error { | ||||
| 		return nil | ||||
| 	case yaml.AliasNode: | ||||
| 		log.Debugf("its an alias!") | ||||
| 		if node.Alias != nil { | ||||
| 			node.Kind = node.Alias.Kind | ||||
| 			node.Style = node.Alias.Style | ||||
| 			node.Tag = node.Alias.Tag | ||||
| 			node.Content = node.Alias.Content | ||||
| 			node.Value = node.Alias.Value | ||||
| 			node.Alias = nil | ||||
| 		} | ||||
| 		return nil | ||||
| 	case yaml.MappingNode: | ||||
| 		for index := 0; index < len(node.Content); index = index + 2 { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user